Get a Value from a Column using Parameter

Posted by T.saravanan under Sql Server category on | Points: 40 | Views : 1762
Hi All,

Here i am give a code for Get a value from a Column using Parameter
Table Name: tbl_Test

Here @sName=sName --> Column Name

Create proc stp_GetValue
@sName varchar(10)
Declare @SqlQuery nVarchar(500),@OutParams nVarchar(500) \\ DataType Must be declare as nVarchar (or) ntext (or) nChar
Declare @sOutput varchar(25)
Set @SqlQuery='SELECT @sValue=(select ['+sName+'] from tbl_Test where Id=1)'
Select @OutParams '@sValue varchar(25) output' \\ For Set a Output Value
exec sp_executesql @SqlQuery, @OutParams,@sOutput output
select @sOutput \\ Get a Value for that Id

I hope this code useful
Thanks :)

Comments or Responses

Login to post response