Is there really any need for this query? I man surely the SQL is it
executing (uurgh, dynamic SQL!) is only really going to be used for one
maybe two tables only?



-----Original Message-----
From: Ray Thompson [mailto:[EMAIL PROTECTED] 
Sent: 11 March 2005 17:50
To: SQL
Subject: RE: Assigning variable with dynamic query

Try this. Notice the added single quotes.

Ray Thompson
Tau Beta Pi (www.tbp.org)
The Engineering Honor Society
865-546-4578 
-----Original Message-----
From: Keith Levenson [mailto:[EMAIL PROTECTED] 
Sent: Friday, March 11, 2005 12:27 PM
To: SQL
Subject: Assigning variable with dynamic query

I can execute a dynamic SQL with the following, but the variable assignment
in the string isn't being assigned:  

        DECLARE @userID as nvarchar(10),
        @myTable as nvarchar(10),
        @strUser as nvarchar(100)
        SET @myTable = 10659
        SET @strUser = N'SELECT ' + @UserID + ' = UserID from my_' +
@myTable + '_user where UserLName = ''Smith'''
        EXEC sp_executesql
        @statement = @strUser

I get this error:  Must declare the variable '@UserID', which is
understandable I guess.  

Does anybody have any ideas for what I am trying to do?

Thanks!

/Keith






~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:6:2207
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/6
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:6
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.6
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to