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 > Direct assignment using SQL statement?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-28-09, 06:15
rpkulkarni rpkulkarni is offline
Registered User
 
Join Date: Nov 2009
Posts: 11
Direct assignment using SQL statement?

Can I accomplish following thing in DB2 stored procedure or functions?

Code:
DECLARE count INTEGER;
..
..
..

SET count = SELECT COUNT(*) from USER_TABLE;
Basically I want to assign the value of number of rows present in USER_TABLE to variable "count". Above statement of course is not working.

Please advise.

Thanks
rpkulkarni
Reply With Quote
  #2 (permalink)  
Old 11-28-09, 06:36
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
SET count = (SELECT COUNT(*) from USER_TABLE);

(SELECT .....) is a scalar full-select. And, scalar full-select is an expression.
Reply With Quote
  #3 (permalink)  
Old 11-28-09, 06:55
rpkulkarni rpkulkarni is offline
Registered User
 
Join Date: Nov 2009
Posts: 11
Thanks for the advise

Thanks for your advise. It worked correctly.

Regards,
rpkulkarni
Reply With Quote
  #4 (permalink)  
Old 11-30-09, 08:40
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Another alternative is a SELECT ... INTO ... statement. It is described in the manual, too.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
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