Link to home
Start Free TrialLog in
Avatar of sarika_patalay
sarika_patalay

asked on

SQL 2005, error with Dynamic SQL

I am writing a procedure which needs table name and col. name to be passed in as variables. I am using dynamic SQL (i dont know if there is any other way). My problem is that when I use the following code, I get an error -

'insert into '+@variable1+
' select * from #table2 where column1 = 'a' and column2 = '+@variable2  

error: Invalid column @variable2.

Can anyone suggest the answer for this? - Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of HuyBD
HuyBD
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial