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 |
Delinda
Constraint Violating Yak Guru
315 Posts |
Posted - 2009-11-08 : 07:45:02
|
My query as follow,declare @SCout varchar(20)declare @ECout varchar(20)set @SCout='KT'set @Ecout='JB'select TID ,sum(case when Cout = @ECout then Posi else 0 end) as @ECout ,sum(case when Cout = @SCout then Posi else 0 end) as @SCoutfrom DERCout_200910group by TIDI got an error -- Incorrect syntax near '@ECout'.How to fix it? I need column name based on variable |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-11-08 : 08:14:17
|
That's only possible with dynamic sql. No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
Delinda
Constraint Violating Yak Guru
315 Posts |
Posted - 2009-11-08 : 11:28:50
|
quote: Originally posted by webfred That's only possible with dynamic sql. No, you're never too old to Yak'n'Roll if you're too young to die.
Yes. You rightTQVM |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-09 : 02:23:51
|
www.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail |
|
|
|
|
|