# Fastest way of adding " " around multiline text in RADRAILS

**URL:** <https://www.ruby-forum.com/t/fastest-way-of-adding-around-multiline-text-in-radrails/89244>\
**Category:** Rails\
**Created:** [March 28, 2006, 5:24pm UTC](https://www.ruby-forum.com/t/fastest-way-of-adding-around-multiline-text-in-radrails/89244 "2006-03-28T17:24:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [March 28, 2006, 5:24pm UTC](https://www.ruby-forum.com/t/fastest-way-of-adding-around-multiline-text-in-radrails/89244/1 "2006-03-28T17:24:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [March 28, 2006, 5:49pm UTC](https://www.ruby-forum.com/t/fastest-way-of-adding-around-multiline-text-in-radrails/89244/2 "2006-03-28T17:49:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [March 29, 2006, 2:18pm UTC](https://www.ruby-forum.com/t/fastest-way-of-adding-around-multiline-text-in-radrails/89244/3 "2006-03-29T14:18:05Z")

</div>

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.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
