troubleshooting Question

SQL 2005, error with Dynamic SQL

Avatar of sarika_patalay
sarika_patalay asked on
DatabasesMicrosoft SQL Server 2005
2 Comments2 Solutions197 ViewsLast Modified:
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.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros