HowTo: Pass a columnname as parametername in stored procedure
Normally you pass values as parameters.
But how can I pass a columnname as parameter in a stored procedure.
The procedure should look like somehow.
select * from A where @columname = 'Test'
Regards,
Maurice
Re: HowTo: Pass a columnname as parametername in stored procedure
Dear Maurice,
You can pass column name as value of Parameter in Stored Procedure but the functionality you want to implement is not possible. You can achieve the functionality by changing your following line with my code:
Your Line of Code
select * from A where @columname = 'Test'
My Line of Code
DECLARE @sqlString VARCHAR(8000)
SET @sqlString = 'select * from A where ' + @columname + ' = ''test'''
execute(@sqlString)
Hope this will solve u r problem.
Re: HowTo: Pass a columnname as parametername in stored procedure
How can the parameter @columnname be descibed in the stored procedure?
Maybe a small example would help.
Is it like??
CREATE PROCEDURE Test
(
DECLARE @sqlString VARCHAR(8000)
@COLUMNNAME varchar(30)
)
AS
SET @sqlString = 'select * from A where ' + @columname + ' = ''test'''
Re: HowTo: Pass a columnname as parametername in stored procedure
Dear Maurice,
No, example like below:
CREATE PROCEDURE Test
(
@COLUMNNAME varchar(30)
)
AS
BEGIN
DECLARE @sqlString VARCHAR(8000)
SET @sqlString = 'select * from A where ' + @columname + ' = ''test'''
execute(@sqlString)
END