How to put in a multi-line string without quotes on each line?

D

dean

sSQL =
" update SELECTED_NODES "
" set LABEL_S = 'Y' "
" where NODE_I in "
" ( "
" select NODE_I "
" from "
" ( "
" select ONODE_I NODE_I from link "
" union all "
" select DNODE_I NODE_I from link "
" ) ALL_NODES "
" group by NODE_I "
" having count(*) > 2 "
" ) ";

Is there a super-quote I can add at the start of that statement, so I
don't need all the double quotes on each line? Something like /* and */
but for strings and not comments.

Thanks!

Dean
 
D

Dennis Jones

dean said:
sSQL =
" update SELECTED_NODES "
" set LABEL_S = 'Y' "
" where NODE_I in "
" ( "
" select NODE_I "
" from "
" ( "
" select ONODE_I NODE_I from link "
" union all "
" select DNODE_I NODE_I from link "
" ) ALL_NODES "
" group by NODE_I "
" having count(*) > 2 "
" ) ";

Is there a super-quote I can add at the start of that statement, so I
don't need all the double quotes on each line? Something like /* and */
but for strings and not comments.

No.

- Dennis
 
J

Jerry Coffin

@i39g2000cwa.googlegroups.com>, (e-mail address removed)
says...
sSQL =
" update SELECTED_NODES "
" set LABEL_S = 'Y' "
" where NODE_I in "
" ( "
" select NODE_I "
" from "
" ( "
" select ONODE_I NODE_I from link "
" union all "
" select DNODE_I NODE_I from link "
" ) ALL_NODES "
" group by NODE_I "
" having count(*) > 2 "
" ) ";

Is there a super-quote I can add at the start of that statement, so I
don't need all the double quotes on each line? Something like /* and */
but for strings and not comments.

I'm not sure it's any improvement in readability, but you
can do something like this:

sSQL = "\
update SELECTED_NODES \
set LABEL_S = 'Y' \
where NODE_I in \
( \
select NODE_I \
from \
( \
select ONODE_I NODE_I from link \
union all \
select DNODE_I NODE_I from link \
) all NODES \
group by NODE_I \
having count(*) > 2 \
)";

This can lead to problems though -- in particular,
inserting white-space between the back-slash and the new-
line can cause a bit of a problem.

My advice would be to read the query in from an external
file instead.
 
L

Larry I Smith

dean said:
sSQL =
" update SELECTED_NODES "
" set LABEL_S = 'Y' "
" where NODE_I in "
" ( "
" select NODE_I "
" from "
" ( "
" select ONODE_I NODE_I from link "
" union all "
" select DNODE_I NODE_I from link "
" ) ALL_NODES "
" group by NODE_I "
" having count(*) > 2 "
" ) ";

Is there a super-quote I can add at the start of that statement, so I
don't need all the double quotes on each line? Something like /* and */
but for strings and not comments.

Thanks!

Dean

This topic may be compiler dependent, I don't know...

The best I could do without getting compile errors was:

const char * sqla =
"update SELECTED_NODES \
set LABEL_S = 'Y' \
where NODE_I in \
( \
select NODE_I \
from \
( \
select ONODE_I NODE_I from link \
union all \
select DNODE_I NODE_I from link \
) ALL_NODES \
group by NODE_I \
having count(*) > 2 \
)" ;

All the above example does is eliminate the leading quote on each
line, but you still must have the trailing backslash on every
line but the last. Also, the final string contains ALL of the blanks
that appear at the beginning of each line.

I'd stay with your original approach; it's easier to read and puts
fewer blanks in the string.

Larry
 
B

benben

dean said:
sSQL =
" update SELECTED_NODES "
" set LABEL_S = 'Y' "
" where NODE_I in "
" ( "
" select NODE_I "
" from "
" ( "
" select ONODE_I NODE_I from link "
" union all "
" select DNODE_I NODE_I from link "
" ) ALL_NODES "
" group by NODE_I "
" having count(*) > 2 "
" ) ";

Is there a super-quote I can add at the start of that statement, so I
don't need all the double quotes on each line? Something like /* and */
but for strings and not comments.

Thanks!

Dean

Put it in a file and read it at run time.

Ben
 
P

Phlip

dean said:
sSQL =
" update SELECTED_NODES "
" set LABEL_S = 'Y' "
" where NODE_I in "
" ( "
" select NODE_I "
" from "
" ( "
" select ONODE_I NODE_I from link "
" union all "
" select DNODE_I NODE_I from link "
" ) ALL_NODES "
" group by NODE_I "
" having count(*) > 2 "
" ) ";

Is there a super-quote I can add at the start of that statement, so I
don't need all the double quotes on each line? Something like /* and */
but for strings and not comments.

That pattern is called PerniciousIngrownSql. You are asking how to make the
SQL easier to in-grow.

Instead, consider writing a simple system that generates SQL with streams,
like this:

stringstream q;
update(q, selectedNodesTable);
q << "set LABEL_S = 'Y'";
q << "where NODE_I in "
selectNode_I(q);

I pushed some of your strings into simple functions. As you write more SQL,
you will re-use these simple functions. If your program grows very complex,
that suite of simple functions will start to work as a "persistence layer".

But if you program does not grow complex (a good thing), then they won't.
They will just keep helping you write SQL statements that don't duplicate
all their contents everywhere.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top