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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Dynamic referencing column names by variable

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-11-13 : 08:06:50
Duane writes "I needed a query to reference a factor earned by months. In 1 table i read the months, integer type. In another table, the data was stored in columns named 1, 2, 3, ... 119, 120. Each of those columns contained the wanted factors. I had to construct a cursor query with a huge Case statement for all 120 columns. Is there any way to reference those columns names dynamically with the variable contents? Agreed that the table could have been better designed, but that was the data that was sent to us. Thanks in advance."

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2003-11-13 : 08:51:53
Only dynamic sql. Put together a string then exec(@string)
Go to Top of Page

SqlStar
Posting Yak Master

121 Posts

Posted - 2003-11-13 : 08:54:16
Hi,

I think its possible, when use Dynamic SQL. So many articles available about Dynamic SQL in this forum.try to see that.

":-) IT Knowledge is power :-)"
Go to Top of Page
   

- Advertisement -