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 |
|
misterjp
Starting Member
4 Posts |
Posted - 2010-12-03 : 00:28:41
|
| Hello,I am trying to find a way to change a column heading dependant on the single result returned.For example:If AvailFunds >= 0, I want the column heading to display 'Account Surplus'but if the AvailFunds < 0, I want the column heading to display 'Account Shortfall'Results should look like this if the AvailFunds >= 0Example #1Client |AccountSurplus123456 |546213.32Example #2Client |AccountShortfall321654 |-1224.57Any help would be greatly appreciated |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-12-03 : 02:05:12
|
you will always have 1 row return in your result ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-12-03 : 02:10:55
|
| [code]SELECT Client, CASE WHEN AvailFunds >= 0 THEN AvailFunds ELSE NULL END AS AccountSurplus, CASE WHEN AvailFunds < 0 THEN AvailFunds ELSE NULL END AS AccountShortfallFROM YourTable[/code]How can you have two column heading for one column in one resultset ?Vaibhav TIf I cant go back, I want to go fast... |
 |
|
|
misterjp
Starting Member
4 Posts |
Posted - 2010-12-05 : 16:33:07
|
| KH: Yes always and only 1 result returned |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2010-12-05 : 16:45:24
|
| change the heading in the client.you could doselect ....into #aif (select AvailFunds from #a >= 0select Client, AccountSurplus from #aelseselect Client, AccountShortfall from #abut I suspect that would cause problems in the client due to the different resultset structures.maybeselect Client, Amt, type = case when AMt >= 0 then 'AccountSurplus' else 'AccountShortfall' endfrom(select Client, Amtfrom ...) a from #a==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|
|
|