Fastest way of adding " " around multiline text in RADRAILS


#1

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.hourstimesheets.cost)
as cost,
sum(items.hours
timesheets.chargedecode(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


#2

Give this a try:

sql_string = <<-_SQL
select timesheets.employee,
sum(items.hours) as hours,
sum(items.hourstimesheets.cost)
as cost,
sum(items.hours
timesheets.chargedecode(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


#3

Chris wrote:

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

Try using this approach (known as a “here document”):

sql = <<‘ENDSQL’
select timesheets.employee,
sum(items.hours) as hours,
sum(items.hourstimesheets.cost)
as cost,
sum(items.hours
timesheets.chargedecode(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