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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2000-11-21 : 22:21:39
|
Charlie Pyne writes "When using sp_executesql in a dynamic stored procedure, are you allowed to use a parameter that represents a column name you want to search???
Heres a simplified version of what I'm trying to do....
CREATE PROCEDURE splookup_order AS
BEGIN DECLARE @SQLString NVARCHAR(1000) DECLARE @ParmDefinition NVARCHAR(500)
SET @sqlstring = N' SELECT * FROM orders AS o WHERE @column_name = @search_for'
SET @parmdefinition = N'@column_name varchar(25), @search_for INT'
EXECUTE sp_executesql @SQLString, @ParmDefinition, @column_name = 'order_number', @search_for = 234
END GO
I picture this example generating.....
SELECT * FROM orders WHERE order_number = 234
but instead it gives me.......
Syntax error converting the varchar value 'order_number' to a column of data type int.
(It works if I just use the 234 as a parameter)
HELP!" |
|
|
|
|
|