Josh R. answered 01/18/21
Full-Stack Ruby Developer
Hello there! You sure can, let me show you.
In your example, it looks like you're executing an SQL statement. Making multi-line SQL statements is actually something I have to do quite often. Ill use your SQL to construct the approach I would use when doing this.
Assuming this logic is wrapped in a class specifically designed to communicate with a database, your conn.exec lives inside a class and a method.
This works, as you probably already know. Now, to your question. You can actually omit the plus signs (+) all together. This also makes formatting with indentations easier. That would look something like this.
One thing you'll notice right off the bat is our SQL statement now looks more like an SQL statement. This will aid in reading and debugging our SQL ( tomorrow and months from now ). Also, depending on what your stack looks like, this has the added benefit of being readable in any logs that show executed SQL. The previous way, with the plus signs, would all end up on the same line in your logs. When you break the lines like this, you get all the white space and new line characters.
IMPORTANT!
In your example, you didn't interpolate anything into your SQL statement. This is perfectly fine because it means you have complete control over what is executed. If you ever decide to create SQL based on user submitted values, I highly recommend you take a serious look at what SQL injection is and how to avoid it.
Hope this helps!