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 > How to select a varible (in a resultset)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-02-07, 07:02
iskander iskander is offline
Registered User
 
Join Date: Sep 2007
Posts: 50
Question How to select a varible (in a resultset)

How can I select a variable into a resultset?
Something like:

BEGIN
DECLARE myVar varchar(100);
SELECT myVar;
END;
Reply With Quote
  #2 (permalink)  
Old 11-02-07, 07:32
iskander iskander is offline
Registered User
 
Join Date: Sep 2007
Posts: 50
I found something that seems to work, which is select varibale from sysibm.sysdummy1
Is this a good practice?
Reply With Quote
  #3 (permalink)  
Old 11-02-07, 07:36
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
"SELECT var;" is not SQL - hence, DB2 does not support it. At least that is good practice.

The purpose of SYSIBM.SYSDUMMY1 is exactly to do what you have in mind. Alternatively, you can do this:
Code:
SET ... = myVar;
Or this:
Code:
VALUES ( myVar );
The latter works on DB2 LUW but not on DB2 z/OS V8 and earlier.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #4 (permalink)  
Old 11-02-07, 08:20
iskander iskander is offline
Registered User
 
Join Date: Sep 2007
Posts: 50
Fantastic!

Thanks
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