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 |
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2013-01-31 : 01:33:42
|
declare @currency nvarchar(3)set @currency = 'USD'select currency from tableAhow can i name the currency column based on currency selected?currencyUSD8010040...if let say set @currency = 'AUS'currencyAUS8010040... |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-31 : 01:45:15
|
you need dynamic sql for thatEXEC('select currency AS currency'+@currency + ' from tableA')------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2013-01-31 : 02:11:36
|
Understood.Thanks! |
|
|
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2013-01-31 : 04:02:38
|
what if to add more column? I tried this but error? need to exec new one?EXEC('select currency AS currency'+@currency +, totalIn+@currency ' from tableA') |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-31 : 04:13:11
|
it should beEXEC('select currency AS currency'+@currency +', totalIn AS totalIn'+@currency + ' from tableA')------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|