comparing multiple rows from multiple columns

  • Hi

    In the Data Warehouse we have recently installed i am trying to reproduce reports produced using SQL that were previously done manuallty in excel.

    (See Code Below)

    from the following table i need someway of identifying the following.

    Only patients that have a discharge and a follwing admission on the same day.

    This can be ID'd by the patient_no and subsiquent adm_no. eg: 45678 - 1, 45678 - 2 and 45678 - 3 Also the previous discharge date for the previous admission must match the new admission date.

    So from the following table i would expect to see results for patients 45678 (admisison 2 & 3) and 54321 (admission 6)

    i have many similar queries like this to set up so any help would greatly appreciated

    CODE BELOW............

    drop table PS_TestForOnline

    CREATE TABLE PS_TestForOnline

    (

    patient_no varchar (10),

    adm_no VARCHAR(5),

    admission_date date ,

    discharge_date date,

    );

    INSERT INTO PS_TestForOnline

    VALUES('12345','1','01/02/2011','08/02/2011' );

    INSERT INTO PS_TestForOnline

    VALUES('45678','1','04/02/2011','04/02/2011' );

    INSERT INTO PS_TestForOnline

    VALUES('45678','2','04/02/2011','04/02/2011' );

    INSERT INTO PS_TestForOnline

    VALUES('45678','3','04/02/2011','06/02/2011' );

    INSERT INTO PS_TestForOnline

    VALUES('54321','5','10/02/2011','10/02/2011' );

    INSERT INTO PS_TestForOnline

    VALUES('54321','6','10/02/2011','11/02/2011' );

    INSERT INTO PS_TestForOnline

    VALUES('12345','2','03/02/2011','05/02/2011' );

    INSERT INTO PS_TestForOnline

    VALUES('12345','3','07/02/2011','10/02/2011' );

    select * from PS_TestForOnline

  • duplicate post. no replies please.

    discussion already started here



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • my mistake, appologies

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply