- Home /

I need to retrieve data in the following order year, startmonth,0, 1, 2, 3, 4 gross, net 2001 ,4, 200, 300,400, 500, 600,7000, (gross-4-3-2-1-0) ) select Startyear,startMonth , sum(case when Months<0 then ep else 0 end) as '<0', sum(case when Months=0 then ep else 0 end) as '0', sum(case when Months=1 then ep else 0 end) as '1', sum(case when Months=2 then ep else 0 end) as '2', sum(case when Months=3 then ep else 0 end) as '3', sum(case when Months=4 then ep else 0 end) as '4', max(Gross)Gross from Ttable this is the query I m using to convert rows to columns - I am stuck how to add the last part where we need to subtract from gross each month value Thanks a lot

Comment

Best Answer

**Answer** by Dave_Green ·

If I'm interpreting your question correctly, you simply want to have max(gross) less the values output as 0,1,2,3 and 4. This would seem to be: max(Gross)-sum(case when Months in (0,1,2,3,4) then ep else 0 end) as [GrossLess0-4], Hope that helps. If I have misunderstood, please rephrase your question so we can see the exact bit you're stuck on.

Copyright 2019 Redgate Software.
Privacy Policy

- Anonymous
- Sign in
- Create
- Ask a question
- Spaces
- Site Issues (NOT FOR DATABASE QUESTIONS)
- Explore
- Topics
- Questions
- Users
- Badges