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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 case problem

Author  Topic 

boris1610
Starting Member

3 Posts

Posted - 2007-10-31 : 11:26:17
Hi every one;
I am new in sql and i can't get this problem fixed. Is there some body who can help me with this problem??????
thanks

I have this query in oracle 10g

select a.Serv_nber, a.rcpt_nber, b.tax_code,
(case when b.tax_code = '01'
then sum(b.tax_amount)
else 0 end) service,
(case when b.tax_code = '08'
then sum(b.tax_amount)
else 0 end) OB
From service a, tax b
where a.year = b.year and
a.branche = b.branche and
a.key_dec = b.key_dec and
a.key_nber = b.key_nber and
a.num = b.num and
a.num = '0' and
a.rcpt_date >= '01-aug-2007' and
a.rcpt_date <= '10-aug-2007' and
Group by a.serv_nber, b.rcpt_nber, b.tax_code


This is what i get

serv_NBER RCPT_NBER Service OB
33553 8212 Fl 375,80 Fl 0,00
33553 8212 Fl 0,00 Fl 0,00
33576 8167 Fl 0,00 Fl 345,40
33576 8167 Fl 725,40 Fl 0,00
33583 8167 Fl 894,90 Fl 0,00
33583 8167 Fl 0,00 Fl 426,10
33584 8167 Fl 0,00 Fl 54,20
33584 8167 Fl 59,60 Fl 0,00


But What I want is this

serv_NBER RCPT_NBER service OB
33553 8212 Fl 375,80 Fl. 0,00
33576 8167 Fl 725,40 Fl. 345,40
33583 8167 Fl. 894,90 Fl. 426,10
33584 8167 Fl. 59,60 Fl. 54,20

nr
SQLTeam MVY

12543 Posts

Posted - 2007-10-31 : 11:29:40
Try
sum(case when b.tax_code = '01'
then b.tax_amount
else 0 end) service,
sum(case when b.tax_code = '08'
then b.tax_amount
else 0 end) OB

p.s. This is a sql server forum :).
Wonder what EL posted for a short time there?

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -