Chris
2006-Mar-28 15:24 UTC
[Rails] Fastest way of adding " " around multiline text in RADRAILS
lets say i have the following SQL in my database editor : When i paste it into rad rails i have to add quotes and the ''+'' symbol to the end of each line. It is very tedious. What is the best method? select timesheets.employee, sum(items.hours) as hours, sum(items.hours*timesheets.cost) as cost, sum(items.hours*timesheets.charge*decode(activities.chargetype,0,1,0)) as charge, sum(items.hours*decode(activities.chargetype,0,1,0)) as chargehours from timesheets, contacts, items, activities, employees, divisions where contacts.com_branch_id = 241 and employees.contact_id = contacts.CONTACT_ID and contacts.expired=0 and timesheets.id = items.timesheet and activities.id = items.activity and employees.id=timesheets.employee and divisions.id=employees.division and timesheets.status = 3 and timesheets.start_date >= ? and timesheets.start_date < ? group by timesheets.employee Thanks, Chris -- Posted via http://www.ruby-forum.com/.
Don Walker
2006-Mar-28 15:49 UTC
[Rails] Fastest way of adding " " around multiline text in RADRAILS
Give this a try: sql_string = <<-_SQL select timesheets.employee, sum(items.hours) as hours, sum(items.hours*timesheets.cost) as cost, sum(items.hours*timesheets.charge*decode(activities.chargetype,0,1,0)) as charge, sum(items.hours*decode(activities.chargetype,0,1,0)) as chargehours from timesheets, contacts, items, activities, employees, divisions where contacts.com_branch_id = 241 and employees.contact_id = contacts.CONTACT_ID and contacts.expired=0 and timesheets.id = items.timesheet and activities.id = items.activity and employees.id=timesheets.employee and divisions.id=employees.division and timesheets.status = 3 and timesheets.start_date >= ? and timesheets.start_date < ? group by timesheets.employee _SQL On 3/28/06, Chris <evilgeenius@gmail.com> wrote:> > lets say i have the following SQL in my database editor : > When i paste it into rad rails i have to add quotes and the ''+'' symbol > to the end of each line. It is very tedious. What is the best method? > > select timesheets.employee, > sum(items.hours) as hours, > sum(items.hours*timesheets.cost) > as cost, > sum(items.hours*timesheets.charge*decode(activities.chargetype,0,1,0)) > as charge, > sum(items.hours*decode(activities.chargetype,0,1,0)) as chargehours > from timesheets, contacts, items, activities, employees, divisions > where > contacts.com_branch_id = 241 and > employees.contact_id = contacts.CONTACT_ID and > contacts.expired=0 and > timesheets.id = items.timesheet and > activities.id = items.activity and employees.id=timesheets.employee and > divisions.id=employees.division and timesheets.status = 3 and > timesheets.start_date >= ? and timesheets.start_date < ? group by > timesheets.employee > > Thanks, > Chris > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060328/f63a6c0f/attachment.html
Justin Forder
2006-Mar-29 12:11 UTC
[Rails] Fastest way of adding " " around multiline text in RADRAILS
Chris wrote:> lets say i have the following SQL in my database editor : > When i paste it into rad rails i have to add quotes and the ''+'' symbol > to the end of each line. It is very tedious. What is the best method? > > select timesheets.employee, > sum(items.hours) as hours, > sum(items.hours*timesheets.cost) > as cost, > sum(items.hours*timesheets.charge*decode(activities.chargetype,0,1,0)) > as charge, > sum(items.hours*decode(activities.chargetype,0,1,0)) as chargehours > from timesheets, contacts, items, activities, employees, divisions > where > contacts.com_branch_id = 241 and > employees.contact_id = contacts.CONTACT_ID and > contacts.expired=0 and > timesheets.id = items.timesheet and > activities.id = items.activity and employees.id=timesheets.employee and > divisions.id=employees.division and timesheets.status = 3 and > timesheets.start_date >= ? and timesheets.start_date < ? group by > timesheets.employeeTry using this approach (known as a "here document"): sql = <<''ENDSQL'' select timesheets.employee, sum(items.hours) as hours, sum(items.hours*timesheets.cost) as cost, sum(items.hours*timesheets.charge*decode(activities.chargetype,0,1,0)) as charge, sum(items.hours*decode(activities.chargetype,0,1,0)) as chargehours from timesheets, contacts, items, activities, employees, divisions where contacts.com_branch_id = 241 and employees.contact_id = contacts.CONTACT_ID and contacts.expired=0 and timesheets.id = items.timesheet and activities.id = items.activity and employees.id=timesheets.employee and divisions.id=employees.division and timesheets.status = 3 and timesheets.start_date >= ? and timesheets.start_date < ? group by timesheets.employee ENDSQL The ENDSQL can be any string you like - it just has to be the same at the start and end. Putting it in single quotes, <<''ENDSQL'', prevents the kinds of interpretation of escape sequences and expression interpolation that Ruby would do on a double-quoted string. regards Justin