I have two tables where one stores DATE,CREDIT and the other stores DATE,DEBIT. I am trying to create a UNION where the result is one table that details the combined information. I can acheive the above using SQL server with the following query:
SELECT distinct
AccountCredits.Date,
AccountCredits.credit,
(NULL)as debit
FROM
Pegasus.dbo.AccountCredits AccountCredits, Pegasus.dbo.AccountDebits AccountDebits
WHERE
AccountCredits.CustomerID = 1 and accountcredits.credit=accountdebits.debit
union
SELECT
AccountDebits.Date,
(NULL)as Credit,
AccountDebits.Debit
FROM
Pegasus.dbo.AccountCredits AccountCredits, Pegasus.dbo.AccountDebits AccountDebits
WHERE
AccountCredits.CustomerID = 1 and accountcredits.credit=accountdebits.debit
The result:
Date credit debit
--------------------------- --------------------- ---------------------
2000-06-01 00:00:00.000 NULL 91.7000
2000-06-14 00:00:00.000 91.7000 NULL
2000-07-03 00:00:00.000 NULL 1.6900
2000-07-12 00:00:00.000 NULL 31.7300
2000-07-19 00:00:00.000 NULL 1.6900
2000-07-22 00:00:00.000 1.6900 NULL
2000-08-01 00:00:00.000 NULL 31.7300
2000-08-14 00:00:00.000 31.7300 NULL
2000-09-11 00:00:00.000 NULL 91.7000
Where columns match, I don't have a problem, but when I have a CREDIT column in one table and a DEBIT column in the other and use UNION, it nags because the there should CREDIT,DEBIT columns in both tables. I need to be able to use '(NULL) as Credit (or Debit) in CR7 but cannot.
Does anyone know a workaround?
Thanks
Richard
[sig][/sig]
SELECT distinct
AccountCredits.Date,
AccountCredits.credit,
(NULL)as debit
FROM
Pegasus.dbo.AccountCredits AccountCredits, Pegasus.dbo.AccountDebits AccountDebits
WHERE
AccountCredits.CustomerID = 1 and accountcredits.credit=accountdebits.debit
union
SELECT
AccountDebits.Date,
(NULL)as Credit,
AccountDebits.Debit
FROM
Pegasus.dbo.AccountCredits AccountCredits, Pegasus.dbo.AccountDebits AccountDebits
WHERE
AccountCredits.CustomerID = 1 and accountcredits.credit=accountdebits.debit
The result:
Date credit debit
--------------------------- --------------------- ---------------------
2000-06-01 00:00:00.000 NULL 91.7000
2000-06-14 00:00:00.000 91.7000 NULL
2000-07-03 00:00:00.000 NULL 1.6900
2000-07-12 00:00:00.000 NULL 31.7300
2000-07-19 00:00:00.000 NULL 1.6900
2000-07-22 00:00:00.000 1.6900 NULL
2000-08-01 00:00:00.000 NULL 31.7300
2000-08-14 00:00:00.000 31.7300 NULL
2000-09-11 00:00:00.000 NULL 91.7000
Where columns match, I don't have a problem, but when I have a CREDIT column in one table and a DEBIT column in the other and use UNION, it nags because the there should CREDIT,DEBIT columns in both tables. I need to be able to use '(NULL) as Credit (or Debit) in CR7 but cannot.
Does anyone know a workaround?
Thanks
Richard
[sig][/sig]