Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Cant pass a variable to an executed sql string?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-11-14 : 15:31:33
chris writes "This i what i am trying to run:

SELECT @SQLStatement = "SELECT * FROM " + @TableName + " WHERE First_Name = '" + @FirstName + "' AND Last_Name = '" + @LastName + "'"

EXEC(@SQLStatement)

This is the error i get:

Server: Msg 207, Level 16, State 3, Line 10
Invalid column name 'SELECT * FROM '.
Server: Msg 207, Level 16, State 1, Line 10
Invalid column name ' WHERE First_Name = ''.
Server: Msg 207, Level 16, State 1, Line 10
Invalid column name '' AND Last_Name = ''.
Server: Msg 207, Level 16, State 1, Line 10
Invalid column name '''.

Any suggestions?"
   

- Advertisement -