sql server - Naming a column as a parameter passed in to a stored procedure -
i have stored procedure takes in parameter @n , @colname , uses @n compute information. right @colname nothing because t-sql not allow make column name parameter. there examples of people saying can through dynamic stored procedure, far can tell, not want.
the reason behind because want create stored procedure uses other stored procedure several times , passes different values of @n , @colname.
so clarify again, able write dynamic stored procedure this:
select a, b, c @colname t1 b = @n
then once can that, write other stored procedure this:
exec stored_procedure1 @n = 3, @colname = 'column 1' exec stored_procedure1 @n = 6, @colname = 'column 2'
any on appreciated. in advance
you need make dynamic query below
exec ('select a, b, c ['+ @colname + '] t1 b = ' + @n)
hope rest can figure out.
Comments
Post a Comment