我的代码有问题,它返回重复值。我试图调整代码,但仍然没有返回我想要的结果。我必须满足五种情况。需要你们的建议或提示。
@BatchID int
--date smalldatetime
AS
--DP to LN
select
a.batch_id,
a.effective_dt,
a.from_acct_no,
e.title_1,
b.iso_code as 'from_currency',
a.from_crncy,
a.to_crncy,
a.to_acct_no,
f.title_1,
c.iso_code as 'to_currency',
a.to_posted_amt,
a.status,
a.rej_reason,
d.short_text,
a.from_description,
a.from_amt,
a.batch_tran_id,
d.error_text
from
gb_batch_tfr_trans a,
ad_gb_crncy b,
ad_gb_crncy c,
pc_ov_error d,
dp_acct e,
ln_acct f
where
a.from_crncy=b.crncy_id
and
a.to_crncy=c.crncy_id
and
d.error_id=*a.rej_reason
and
a.status in ('rejected')
and
a.from_acct_no*=e.acct_no
and
a.to_acct_no*=f.acct_no
and
a.batch_id= @BatchID
union all
--GL 到 GL
select
a.batch_id,
a.effective_dt,
a.from_acct_no,
g.description as 'Fromacc',
b.iso_code as 'from_currency',
a.from_crncy,
a.to_crncy,
a.to_acct_no,
h.description as 'Toacc',
c.iso_code as 'to_currency',
a.to_posted_amt,
a.status,
a.rej_reason,
d.short_text,
a.from_description,
a.from_amt,
a.batch_tran_id,
d.error_text
from
gb_batch_tfr_trans a,
ad_gb_crncy b,
ad_gb_crncy c,
pc_ov_error d,
gl_acct g,
gl_acct h
where
a.from_crncy=b.crncy_id
and
a.to_crncy=c.crncy_id
and
d.error_id=*a.rej_reason
and
a.status in ('rejected')
and
a.from_acct_no*=g.acct_no
and
a.to_acct_no*=h.acct_no
and
a.batch_id= @BatchID
union all
---GL转DP
select
a.batch_id,
a.effective_dt,
a.from_acct_no,
g.description as 'Fromacc',
b.iso_code as 'from_currency',
a.from_crncy,
a.to_crncy,
a.to_acct_no,
h.title_1 as 'Toacc',
c.iso_code as 'to_currency',
a.to_posted_amt,
a.status,
a.rej_reason,
d.short_text,
a.from_description,
a.from_amt,
a.batch_tran_id,
d.error_text
from
gb_batch_tfr_trans a,
ad_gb_crncy b,
ad_gb_crncy c,
pc_ov_error d,
gl_acct g,
dp_acct h
where
a.from_crncy=b.crncy_id
and
a.to_crncy=c.crncy_id
and
d.error_id=*a.rej_reason
and
a.status in ('rejected')
and
a.from_acct_no*=g.acct_no
and
a.to_acct_no*=h.acct_no
and
a.batch_id= @BatchID
union all
--DP转GL
select
a.batch_id,
a.effective_dt,
a.from_acct_no,
g.title_1 as 'Fromacc',
b.iso_code as 'from_currency',
a.from_crncy,
a.to_crncy,
a.to_acct_no,
h.description as 'Toacc',
c.iso_code as 'to_currency',
a.to_posted_amt,
a.status,
a.rej_reason,
d.short_text,
a.from_description,
a.from_amt,
a.batch_tran_id,
d.error_text
from
gb_batch_tfr_trans a,
ad_gb_crncy b,
ad_gb_crncy c,
pc_ov_error d,
dp_acct g,
gl_acct h
where
a.from_crncy=b.crncy_id
and
a.to_crncy=c.crncy_id
and
d.error_id=*a.rej_reason
and
a.status in ('rejected')
and
a.from_acct_no*=g.acct_no
and
a.to_acct_no*=h.acct_no
and
a.batch_id= @BatchID
union all
--GL 到 LN
select
a.batch_id,
a.effective_dt,
a.from_acct_no,
g.description as 'Fromacc',
b.iso_code as 'from_currency',
a.from_crncy,
a.to_crncy,
a.to_acct_no,
h.title_1 as 'Toacc',
c.iso_code as 'to_currency',
a.to_posted_amt,
a.status,
a.rej_reason,
d.short_text,
a.from_description,
a.from_amt,
a.batch_tran_id,
d.error_text
from
gb_batch_tfr_trans a,
ad_gb_crncy b,
ad_gb_crncy c,
pc_ov_error d,
gl_acct g,
ln_acct h
where
a.from_crncy=b.crncy_id
and
a.to_crncy=c.crncy_id
and
d.error_id=*a.rej_reason
and
a.status in ('rejected')
and
a.from_acct_no*=g.acct_no
and
a.to_acct_no*=h.acct_no
and
a.batch_id= @BatchID