Good Day,
I'm Trying to pass parameters to represent a column name and value to a stored procedure to execute but havinfg difficulties... can anyone help?
I'm Trying to pass parameters to represent a column name and value to a stored procedure to execute but havinfg difficulties... can anyone help?
Code:
declare @columnName as nvarchar(30)
declare @value as nvarchar(30)
declare @condition as nvarchar(10)
set @columnName = 'last_name'
set @type = 'LIKE'
set @condition = '%g%'
-- Create a variable @SQLStatement
DECLARE @SQLStatement varchar(255)
SELECT @SQLStatement = 'select * from Users where ' + @columnName + ' ' + @type + ' ' + '' + @value + ''
-- Execute the SQL statement
EXEC(@SQLStatement)
Comment