March 9, 2015 at 1:48 pm
Hi,
I have this statement:
SELECT top 100 P.LastName ,
P.FirstName,
P.MiddleName,
P.PractitionerTypeID,
P.SuffixID,
A.Linenumber1,
A.LineNumber2,
Z.City,
Z.State,
Z.ZipCode,
Z.County,
P.NationalProviderID,
PIS.LegalName,
PLS.LocationName
FROM dbo.Practitioners AS P LEFT OUTER JOIN
dbo.PractitionerLocations AS PL ON P.PractitionerID = PL.PractitionerID LEFT OUTER JOIN
dbo.PracticeLocations AS PLS ON PL.LocationID = PLS.LocationID LEFT OUTER JOIN
dbo.Addresses AS A ON PLS.AddressID = A.AddressID LEFT OUTER JOIN
dbo.ZipCodes AS Z ON A.ZipCodeID = Z.ZipCodeID
It returns the correct records but when I add a join - it creates duplicates. I have tried a few different joins like this:
FROM dbo.Practitioners AS P LEFT OUTER JOIN
dbo.PractitionerLocations AS PL ON P.PractitionerID = PL.PractitionerID LEFT OUTER JOIN
dbo.PracticeLocations AS PLS ON PL.LocationID = PLS.LocationID LEFT OUTER JOIN
dbo.Addresses AS A ON PLS.AddressID = A.AddressID LEFT OUTER JOIN
dbo.ZipCodes AS Z ON A.ZipCodeID = Z.ZipCodeID RIGHT OUTER JOIN
dbo.Practices AS PIS ON PLS.PracticeID = PIS.PracticeID[/code]
Seems like no matter which join type I choose i still get duplicates. Not sure what I am not seeing here.
March 9, 2015 at 2:36 pm
a practitioner could have more than one location; you know, he works at Baptist East, Baptist North and Baptist South, so that would be normal to see the same provider multiple times, due to locations.
if your locations data was not clean, meaning there was more than one duplicate address, that would also explain "duplicates";
so if someone had inserted Baptist North as a location twice.
so are you seeing true duplicates, or data you don't expect /want to see?
Lowell
March 9, 2015 at 6:34 pm
Check for uniqueness of PracticeID in dbo.Practice
_____________
Code for TallyGenerator
March 10, 2015 at 8:07 am
Thanks Lowell and Sergiy.
I assumed the ID values were being forced they were not.
Thanks again guys.
March 10, 2015 at 1:31 pm
Lowell (3/9/2015)
a practitioner could have more than one location; you know, he works at Baptist East, Baptist North and Baptist South, so that would be normal to see the same provider multiple times, due to locations.if your locations data was not clean, meaning there was more than one duplicate address, that would also explain "duplicates";
so if someone had inserted Baptist North as a location twice.
so are you seeing true duplicates, or data you don't expect /want to see?
Hi Lowell,
I need to use this data to import into a different Database via SSIS (or script). So, you I think you are spot on the practitioner is listed 10 times because he has 10 offices. But in a SSIS package how would I import the doctor one time and his offices 10 times? Is there a way in SSIS that can handle that senario? Or do I need to break it in the script somehow?
March 10, 2015 at 1:35 pm
yes, it's certainly possible.
i was thinking import down bloew but you mena tto export.
you want to select distinct provider, base don NPI number, as oneexport, adn a seperate export for locaitons, i hthink.
this was my old thoughts, where i was thinking IMPORT.
if you are not using a staging table in SQL, where you could run a group by, and then a seperate select, you can use a multi cast.
you multicast to an aggregate to group by say, NPI number of the physician, which eliminates dupes, and a seperate cast to the locations
Lowell
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply