May 20, 2010 at 11:00 am
I have an account master table that has a start date, but this start date can be changed at any point in time.
I want to grab all accounts from the account master table that don't have any transactions in the transaction table prior to the start date.
Acct Table
--------------------
Acct Start Date
1000 2010-01-01
1001 2010-01-01
1002 2010-01-01
Trans Table
--------------------------
Acct TransDesc Date
1000 Hello there 2009-01-15
1000 Hi 2009-01-10
1002 Yo 2009-10-10
1001 This ONE! 2010-01-02
So in the above example only acct 1001 would get returned.
May 20, 2010 at 11:21 am
--results
Acct TransDesc Date Acct StartDate
1001 This ONE! 2010-01-02 00:00:00.000 1001 2010-01-01 00:00:00.000
the example:
CREATE TABLE Acct(Acct int, StartDate datetime )
INSERT INTO Acct
SELECT '1000','2010-01-01' UNION ALL
SELECT '1001','2010-01-01' UNION ALL
SELECT '1002','2010-01-01'
CREATE TABLE Trans (Acct int, TransDesc varchar(30), Date datetime)
INSERT INTO Trans
SELECT '1000','Hello there','2009-01-15' UNION ALL
SELECT '1000','Hi','2009-01-10' UNION ALL
SELECT '1002','Yo','2009-10-10' UNION ALL
SELECT '1001','This ONE!','2010-01-02'
SELECT * FROM Trans
LEFT OUTER JOIN Acct
ON Trans.Acct = Acct.Acct
WHERE Trans.Date >= Acct.StartDate
Lowell
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply