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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-03-16 : 08:33:45
|
| Tom writes "I wish to create a workfile from a normalized database that both SUMs data and conditionally creates aggregate (SUM) columns within one Select statement. (ie. SELECT CustomerID, AdjustmentType, SUM(AdjustmentAmount) as Total_adjustments From ADJUSTMENTS Group By CustomerID), AdjustmentType) I would like to "flatten" out the resulting set with columns for type 1, 2, 3, 4, and other with a CASE Statement imbedded in the SELECT. Something Like....SUM(CASE AdjustmentType WHEN 1 THEN AdjustmentAmount ELSE ?) AS CreditSUM(CASE AdjustmentType WHEN 2 THEN AdjustmentAmount ELSE ?) AS DebitSUM(CASE AdjustmentType ELSE..... AS Otheror to create summary colums my months like:SUM(CASE mnth WHEN 1 THEN sales ELSE NULL END) AS jan,etcIs this possible? Or am I dreaming?ThanksTom" |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-03-16 : 08:38:13
|
| yes that's how you do it ... did you try it?- Jeff |
 |
|
|
|
|
|