Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sql: getting one row separated and sumarized by month. 1

Status
Not open for further replies.

jonasggg

Technical User
Sep 30, 2003
12
0
0
UY
Hello!

Is there a sql to do like this using one table and all this months columns in one row?

TABLE structure:
Client_id --- Date ---- TOTAL
150 --- 01/JAN/2005 ---- 10$
150 --- 05/JAN/2005 ---- 5$

(15$ in JANUARY for Client_id 150)



Year: 2005
Client_id - JAN - FEB - MAR - APR - MAY - JUN - JUL - AGO - SET - OCT - NOV - DIC
150 - 15$ - 20$ - 10$ - 13$ - 18$ - 14$ - 20$ - 10$ - 50$ - 80$ - 11$ - 5$

(15$ in JANUARY for Client_id 150)


Thanks in advance!
 
Try this to get the results with plain sql:
Code:
select      clientID,
            sum(case when datepart(month, date) = 1 then Total else 0 end) 'Jan',
            sum(case when datepart(month, date) = 2 then Total else 0 end) 'Feb'
            -- so on until Dec
fromT       TableA
where       year(date) = year(getdate())
group by    clientID

Regards,
AA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top