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
 datatype to store column name

Author  Topic 

karthick.amace
Starting Member

23 Posts

Posted - 2010-07-23 : 20:46:54
Hi brothers
I want to know the datatype which is used to store the column name of table. Because I want to use that column name in my Update statement
Plz help me and suggest me to do..

sample
Declare @colname ?????
Set @colname=(SELECT c.name FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE t.name='Acomp' and c.name=1)

Update Acomp
Set @colname=5
Where empid=101

my column will be like numbers eg.,[1],[2],[3]...
wherevr my input values and colname mayches I want to update the value
this is the requirement

I tried this,
unfortunately is not worked
DECLARE @temp sysname
SET @temp=(SELECT c.name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE t.name='Acomp' and c.name=1)

update AComp
set @temp=5
where empid=101

I thnk it taking @temp as some temp variable not as column...

Plz let me know is that possible...?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2010-07-23 : 22:58:56
Please do not cross post:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=147733
Go to Top of Page
   

- Advertisement -