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
 Eliminating some documents

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2008-12-08 : 08:12:53
Hi friends,
I need to eliminate some document based on the type (ie) 'CC'
when @type='CC' the documents from MIS_CASH_FLW_TB should not be considered/taken based on the join (document,fbid)

Can anyone correct the below query:



Declare @type char(2)
set @type='CC'


select
fb_id,
account_code,
sum(base_amount)
from Mis_Revenue_tb (nolock)A
where
case
when @type='CC' then
fb_voucher_no not in(
select docno from MIS_CASH_FLW_TB(nolock) B
where a.fb_voucher_no=b.docno
and a.fb_id=b.fbid
) and
company_code like '%'
and fb_id like '%'
and a.posting_date between '01 apr 2008' and '30 jun 2008'
group by fb_id,account_code
else

company_code like '%'
and fb_id like '%'
and a.posting_date between '01 apr 2008' and '30 jun 2008'
group by fb_id,account_code

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-08 : 08:27:44
[code]Declare @type char(2)
set @type='CC'


select
fb_id,
account_code,
sum(base_amount)
from Mis_Revenue_tb (nolock)A
where
(fb_voucher_no not in(
select docno from MIS_CASH_FLW_TB(nolock) B
where a.fb_voucher_no=b.docno
and a.fb_id=b.fbid
) or @type<>'CC')

and
company_code like '%'
and fb_id like '%'
and a.posting_date between '01 apr 2008' and '30 jun 2008'
group by fb_id,account_code
[/code]
Go to Top of Page
   

- Advertisement -