If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Stored procedure - multi line string in set statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-15-08, 11:14
hifferyj hifferyj is offline
Registered User
 
Join Date: Oct 2008
Posts: 19
Stored procedure - multi line string in set statement

Hi,

I have somewhat of a large query that I need to put into a variable so I can prepare it.

What I'd like to do, so I don't lose all the formatting, is say something like this:

SET var = "select col1, col2, col3,nullif('','')
from table
where col1 in (1,2,3,4,5,6)";

Data Studio Developer gets angry with me because of the multi line aspect of this.

I Think this works

SET var = "select col1, col2, col3,nullif('','')" ||
" from table" ||
" where col1 in (1,2,3,4,5,6)";

Is there an easier and less sloppy way to do this?

--------------------------------------------------------

In case you're curious about the entire issue:


I'm first dynamically building a key list. But for the sake of my question:

SET keylist = "1,2,3,4,5";

SET keys = "(" || keylist || ")";

Then injecting keys into the select statement stored in "var".

Then I'm going to prepare it and run it to return rows. But keep in mind, my main question is how to set a string variable to multiple rows of text easily.

Thanks,
Joe
Reply With Quote
  #2 (permalink)  
Old 10-15-08, 11:29
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
No, there is no other way to setup the string.

Andy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On