By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,924 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,924 IT Pros & Developers. It's quick & easy.

how to set variable using dynamic sql

P: n/a
If I have the line following in a stored proc...
set rowCount = (select count(*) from t2);

what is the equivalent way to set rowCount variable using dynamic sql...
...
set sqlStmt = 'select count(*) from t2';
EXECUTE IMMEDIATE sqlStmt;
...

Thanks, Bill
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Bill Smith wrote:
If I have the line following in a stored proc...
set rowCount = (select count(*) from t2);

what is the equivalent way to set rowCount variable using dynamic sql...
..
set sqlStmt = 'select count(*) from t2';
EXECUTE IMMEDIATE sqlStmt;
..

Thanks, Bill

The next statement can be:

GET DIAGNOSTICS rowCount = ROW_COUNT;

or you can instead do:

DECLARE v_stmt STATEMENT;
DECLARE c1 CURSOR FOR v_stmt;
....
PREPARE v_stmt FROM sqlStmt;
OPEN c1;
FETCH c1 INTO rowCount;
--
Rob Wilson
ro********@ameritech.net.invalid (remove .invalid)
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.