|
Thanks Joe & Rick.
Joe, it worked perfectly after I put the comma back in after the
first CTE.
Joe Pluta wrote:
-- Get accounts with at least one of each
with T1 as (
select ACCT# from AcctTbl
where ACCT# in (select ACCT# from Conttbl)
and ACCT# in (select ACCT# from DistTbl)),
-- Create list of transactions
T2 as (
select 1 FileID, T1.ACCT#, CONTR$, 0 DIST$
from T1 join ContTbl on T1.ACCT# = ContTbl.ACCT#
union all
select 2 FileID, T1.ACCT#, 0 CONTR$, DIST$
from T1 join DistTbl on T1.ACCT# = DistTbl.ACCT#)
-- Now list the results
select ACCT#, CONTR$, DIST$ from T2
order by FileID
You may need a little tweaking to make sure the columns match in the two selects for the union in T2, but this is the general
idea. I am a big fan of common table expressions. They work
wonders.
Jack Prucha wrote:
I'm trying to select a list that looks like this:
Acct# Contr$ Dist$
00001 15.00
00001 28.00
00001 30.00
00005 10.00
00005 25.00
etc.
Select accts with at least one contribution and one distribution and list them all. The contribution and
distributions can be on the same line or individual lines,
but there's no matching of them. The selection will be by
date ranges also.
There are three separate tables that look something like
these:
AcctTbl
Acct#
ContTbl
Acct#, Contr$, ContrDate
DistTbl
Acct#, Dist$, DistDate
I can figure out the where exists to select the accounts
but how do I join these together to get the details?
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.