logo       

Using dynamic SQL to set a variable: msg#00096

Subject: Using dynamic SQL to set a variable

This is too weird.  I'm trying to loop through my tables to get row 
counts.  I have a cursor which runs through the tables fine.  In the 
loop, I execute this statement:

SET @rowCount = EXEC ('SELECT COUNT(*) FROM ' + @tableName)

and I get an error saying that there is Incorrect syntax near the 
keyword 'EXEC'.  However, if I just run the statement:

EXEC ('SELECT COUNT(*) FROM ' + @tableName)

it works fine.  Can't I set a variable using dynamic SQL this way?  I 
was sure I had done it before...

KRP





------------------------ Yahoo! Groups Sponsor --------------------~--> 
$4.98 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/Q7_YsB/neXJAA/yQLSAA/dpFolB/TM
--------------------------------------------------------------------~-> 

 


<Prev in Thread] Current Thread [Next in Thread>