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)
 Using variable as a column name without case statement

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-12-11 : 09:42:09
Tim Pilkington writes "This is the only thing I could find on this problem

Select CODE,TITLE,Version,Status,
Case @Price
When 'Price' THEN Price
When 'PriceA' Then PriceA
When 'PriceB' Then PriceB
When 'PriceC' Then PriceC
End,
Lots,
LotsOf,
Description,
....

Is there a way of doing away with the case statement as all it does is translate the @Price variable into a column name and the column name is the same as the string held in @Price?

What I need is something like
Select ColA, ColB, (@variable), ColD....

Is this possible and if so how?

(SQL Server 7)

Thanks a lot."

squisher
Starting Member

6 Posts

Posted - 2001-12-11 : 10:13:56
Something like this might work.

SELECT @SQLSTATEMENT = ('SELECT ' + @Price + ' FROM myTable')
EXECUTE sp_executesql @SQLSTATEMENT



-Stefan-

Go to Top of Page
   

- Advertisement -