Saturday, February 11, 2012

@NUM_MEMBERS = EXEC (USE +@X + ; SELECT COUNT(Member_Name) FROM Logins) -HOW?

DECLARE @.X VARCHAR(10)
DECLARE @.NUM_MEMBERS SMALLINT
SELECT @.X = 'other_db'

@.NUM_MEMBERS = EXEC ('USE ' +@.X + '; SELECT COUNT(Member_Name) FROM Logins')

I get an error when I try to store the result in @.NUM_MEMBERS. :/ I've been looking all over for the correct syntax. Can anyone help?

ERROR:
Server: Msg 170, Level 15, State 1, Line 6
Line 6: Incorrect syntax near '@.NUM_MEMBERS'.

thx n advits probably better just to use sp_executesql, eh?|||I think you have to to get results back in variables from a dynamic SQL string.

No comments:

Post a Comment