Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 stored procedure

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-09-19 : 07:40:07
rahul writes "Hi all,

i am new to mssql server and fethcing following
problem

there are one table contains the columns

AppID,email,phone,faxNo,OtherContact

User is passing column name to following sp

e.g. exec test '104','faxNo'

Now i have to retrive data from that particular column and
appNo in sp and dump it into another table


e.g.
appNo email phone faxNo otherContact
104 fsfs 434 344 fsdfsd



one store procedure as follows



create procedure test(@AppNo varchar(50),@Arg1 varchar(50))
AS

Begin
Declare @data varchar(50)


@data= (what should i write to get 344 for the mentioned example)

End

"

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-19 : 07:58:31
You will have to make use of Dynamic SQL as follows:

EXEC('Select ' + @Arg1 + ' from Tbl where AppId = ''' + @AppNo + '''')


Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page
   

- Advertisement -