You can't do it like that. It will not do symbolic substitution like that.
You need touse something like:
Note the ' ' round the LIKE clause - you'd missed that out. Also note the brackets in EXEC(@sqlstr) - that tells it it is a character string to be interpreted.Code:CREATE PROCEDURE Test @field varchar(100), @condition varchar(100) AS DECLARE @sqlstr varchar(100) BEGIN SET @sqlstr = "SELECT * FROM Job WHERE " + rtrim(@field) + "='" + rtrim(@condition) + "'" EXEC (@sqlstr) END
Cheers,
P.




Reply With Quote