Howdy all,
I'm trying to create a sproc that has the column name and search text as input parameters with dynamic SQL... what I have is:
-- Create a variable @.SQLStatement
DECLARE @.SQLStatement varchar(255)
SELECT @.SQLStatement = 'SELECT * FROM myTable WHERE (''' + @.ColumnName + ''' = ''' + @.SearchText + ''')'
-- Execute the SQL statement
EXEC(@.SQLStatement)
The procedure works (at least in Query Analyzer, once I declare/set @.columnname and @.searchtext) in that I don't get any errors. But it returns a blank table with "0 rows affected". However, if I hardcode the variables, it returns the proper data. What's wrong with my select statement??
Thanks!!
JP
SET @.SQLStatement = 'SELECT * FROM myTable WHERE (' + @.ColumnName + ' = ''' + @.SearchText + ''')'
-- Execute the SQL statement
EXEC(@.SQLStatement)|||That's it! Thanks, ndinakar. Those darn quotes...
No comments:
Post a Comment