Need help with SQL to get duplicate rows and still show unique fields in the rows and filter by NULL field when one or both are NULL

  • ChrisM@Work (1/14/2016)


    wolfgheist (1/14/2016)


    ChrisM@Work (1/14/2016)


    wolfgheist (1/14/2016)


    I am playing around with it, but it keeps pulling too much data. It is pulling 20k+ rows, when my first script above pulls 4302 rows that contains all of the data including when the discharge data is populated for both records which I do not want and the second pulls 1302 rows, but is missing the Whendischarged when one is Null and one has a value.

    Bear in mind that your script doesn't work correctly (or you wouldn't be here).

    I fully agree 🙂

    wolfgheist (1/14/2016)


    In Summary I want rows where the FIN and MRN are exact matches (There are only two rows for each patient with duplicate data). I want FirstName and LastName even if they do not match. I want WhenDischarged when both are NULL, when one is NULL, but not when both are not NULL

    Since the last script I posted does exactly this (without eliminating the rows from the output), can you add rows to the sample data section to show how the script isn't working?

    Well it displayed some things that do not quite match up with what I am looking for. I have spaced them in sets of what I am looking for and what I do not want.

    123450012345JohnSmitheNULL1YES - I want this row

    123450012345JohnSmithNULL2NO - I want this row

    123460012346JaneDoeNULL1YES - I want this row

    123460012346JaneDoe2016-01-012NO - I want this row

    123470012347JohnDoeNULL1YES - I want this row

    123470012347JohnDoe2016-01-022NO - I want this row

    123480012348JaneySmith2016-01-011NO - I do not want this row

    123480012348JaneSmith2016-01-012NO - I do not want this row

    So you want ALL row pairs, except where WhenDischarged for both rows of a pair is not null?

    Hi Chris, yes that is correct. My apologies that I was not clear in my question.

Viewing post 16 (of 16 total)

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