• adonetok (8/14/2012)


    Thank you. I almost get there.

    But, if I inserted more values, the duplicate result will displays.

    How to fix it?

    INSERT INTO dbo.PatientInfo

    VALUES ('06000248','08/02/2010','08/04/2010'),

    ('06000248','08/10/2010','08/12/2010'),

    ('06000248','08/20/2010','08/22/2010'),

    ('06000348','08/02/2011','08/04/2011'),

    ('06000348','08/10/2011','08/12/2011'),

    ('06000348','08/20/2011','08/22/2011');

    GO

    MEMBID ADMDATE DSCHDATEDaysOut

    060002482010-08-022010-08-040

    060002482010-08-102010-08-126

    060002482010-08-102010-08-12-359

    060002482010-08-202010-08-228

    060002482010-08-202010-08-22-357

    060003482011-08-022011-08-040

    060003482011-08-102011-08-12371

    060003482011-08-102011-08-126

    060003482011-08-202011-08-22373

    060003482011-08-202011-08-228

    You tell me, are duplicate records allowed? Your original sample data set did not have duplicates. If duplicates can exist, what are your business rules regarding them, can you eliminate them prior to processing or do you have work them and if so what are the rules for dealing with duplicates.

    Nevermind the above, small font on a small screen (laptop) didn't realize the account numbers were different. Yes, to the below, we need to add a bit more to the join criteria.