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.
| Author |
Topic |
|
jaimealvarez
Starting Member
31 Posts |
Posted - 2012-07-25 : 13:16:00
|
| I have this code (it s whitihn a CTE):SELECT c.crclient, c.crmaximum, c.RateCodeKey, CASE WHEN c.crrtnum IS NOT NULL then (select timerate.tkrt12 from timerate WHERE (tkinit='01357')) I want to know if I can make the column name "timerate.tkrt12" dynamic, based on the value of c.RateCodeKey. The value of c.RateCodeKey can be timerate.trkrt12, timerate.trkrt13, etc.Any help would be appreciated.Thanks. |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2012-07-25 : 13:20:17
|
| possibly an inner join to a derived table instead of a case statement might work.How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-25 : 14:04:39
|
quote: Originally posted by jaimealvarez I have this code (it s whitihn a CTE):SELECT c.crclient, c.crmaximum, c.RateCodeKey, CASE WHEN c.crrtnum IS NOT NULL then (select timerate.tkrt12 from timerate WHERE (tkinit='01357')) I want to know if I can make the column name "timerate.tkrt12" dynamic, based on the value of c.RateCodeKey. The value of c.RateCodeKey can be timerate.trkrt12, timerate.trkrt13, etc.Any help would be appreciated.Thanks.
this doesnt make any sensewhats relation b/w timerate and your main table referred by alias c. without any relation you cant select column from it based on c column value------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|