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
 Select @Local-Variable From TestTable.!!!?

Author  Topic 

ZarrinPour
Yak Posting Veteran

66 Posts

Posted - 2007-10-07 : 15:56:09
Hi all
Imagine we have a table as follow:

Create Table Test(
Pkey int not Null identity Primary Key,
Name varchar(20) not null,
Famil varchar(30) not null
)

now is there anyway to Run following Script:

declare @FLDName varchar(10)
set @FLDName='Name'
Select @FLDName from Test

in the other hand is there anyway to use Local variables in a SELECT statements as above?
to tell you the truth , what really motivated me to do this , was being able to declare a User-Defined-Function and passing some fields as an String and then use them in a SELECT statement or any other T-Sql codes!!!

Could anyone help me.?
Kind Regards.

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-10-07 : 16:00:38
read this:

http://www.sommarskog.se/dynamic_sql.html


elsasoft.org
Go to Top of Page
   

- Advertisement -