That's what I want to do, as per an example in the BOL:
DECLARE @IntVariable INT DECLARE @SQLString NVARCHAR(500) DECLARE @ParmDefinition NVARCHAR(500)
/* Build the SQL string once.*/ SET @SQLString = N'SELECT * FROM pubs.dbo.employee WHERE job_lvl = @level' SET @ParmDefinition = N'@level tinyint' /* Execute the string with the first parameter value. */ SET @IntVariable = 35 EXECUTE sp_executesql @SQLString, @ParmDefinition, @level = @IntVariable /* Execute the same string with the second parameter value. */ SET @IntVariable = 32 EXECUTE sp_executesql @SQLString, @ParmDefinition, @level = @IntVariable
As you can see, the string @level get replaced by the parameter @IntVariable,
in my case I want @string to be replaced by @where
It works as expected in the first example...
Set @SQLString = 'print @String '
Dave J