I have a query to select list of patients based on some condition. But I need to delete those instead of selecting. Here is the query:
SELECT
[p].[Patient_ID],
[p].[Last_Name],
[p].[First_Name],
[p].[MI]
FROM [Coupon].[dbo].[Patient] AS [p]
JOIN [Coupon].[dbo].[Patient_PLPPrescriberSite_Xref] AS [ppsx] ON ([ppsx].[PatientID]=[p].[Patient_ID])
JOIN [TCPLP].[dbo].[PrescriberSiteXref] AS [psx] ON ([psx].[PrescriberSiteXrefID]=[ppsx].[HCP_PLP_EnrollmentPrescriberSiteXrefID])
JOIN [TCPLP].[dbo].[PrescriberSite] AS [ps] ON ([ps].[PrescriberSiteID]=[psx].[PrescriberPersonID])
JOIN [TCPLP].[dbo].[Person] AS [ph] ON [PersonID]=[psx].[PrescriberPersonID]
WHERE
([ps].[Description] IN ('n/a', 'N/A', ' ')) OR ([ps].[Description] LIKE '0%')
OR ([ph].[LastName] IN ('n/a', 'N/A', ' ')) OR ([ph].[LastName] LIKE '0%')
SELECT
[p].[PersonID],
[p].[LastName],
[p].[FirstName],
[p].[MiddleName]
FROM
[R2].[dbo].[Person] AS [p]
JOIN [R2].[dbo].[R2EnrollmentSiteDetails] AS [esd] ON ([esd].[PatientID]=[p].[PersonID])
JOIN [TCPLP].[dbo].[PrescriberSiteXref] AS [psx] ON ([psx].[PrescriberSiteXrefID]=[esd].[TP_PLPPrescriberSiteXrefID])
JOIN [TCPLP].[dbo].[PrescriberSite] AS [ps] ON ([ps].[PrescriberSiteID]=[psx].[PrescriberSiteID])
JOIN [TCPLP].[dbo].[Person] AS [ph] ON ([ph].[PersonID]=[psx].[PrescriberPersonID])
WHERE
([ps].[Description] IN ('n/a', 'N/A', ' ')) OR ([ps].[Description] LIKE '0%')
OR ([ph].[LastName] IN ('n/a', 'N/A', ' ')) OR ([ph].[LastName] LIKE '0%')
Can anyone tell me the query plzzz
Thanks
SELECT
[p].[Patient_ID],
[p].[Last_Name],
[p].[First_Name],
[p].[MI]
FROM [Coupon].[dbo].[Patient] AS [p]
JOIN [Coupon].[dbo].[Patient_PLPPrescriberSite_Xref] AS [ppsx] ON ([ppsx].[PatientID]=[p].[Patient_ID])
JOIN [TCPLP].[dbo].[PrescriberSiteXref] AS [psx] ON ([psx].[PrescriberSiteXrefID]=[ppsx].[HCP_PLP_EnrollmentPrescriberSiteXrefID])
JOIN [TCPLP].[dbo].[PrescriberSite] AS [ps] ON ([ps].[PrescriberSiteID]=[psx].[PrescriberPersonID])
JOIN [TCPLP].[dbo].[Person] AS [ph] ON [PersonID]=[psx].[PrescriberPersonID]
WHERE
([ps].[Description] IN ('n/a', 'N/A', ' ')) OR ([ps].[Description] LIKE '0%')
OR ([ph].[LastName] IN ('n/a', 'N/A', ' ')) OR ([ph].[LastName] LIKE '0%')
SELECT
[p].[PersonID],
[p].[LastName],
[p].[FirstName],
[p].[MiddleName]
FROM
[R2].[dbo].[Person] AS [p]
JOIN [R2].[dbo].[R2EnrollmentSiteDetails] AS [esd] ON ([esd].[PatientID]=[p].[PersonID])
JOIN [TCPLP].[dbo].[PrescriberSiteXref] AS [psx] ON ([psx].[PrescriberSiteXrefID]=[esd].[TP_PLPPrescriberSiteXrefID])
JOIN [TCPLP].[dbo].[PrescriberSite] AS [ps] ON ([ps].[PrescriberSiteID]=[psx].[PrescriberSiteID])
JOIN [TCPLP].[dbo].[Person] AS [ph] ON ([ph].[PersonID]=[psx].[PrescriberPersonID])
WHERE
([ps].[Description] IN ('n/a', 'N/A', ' ')) OR ([ps].[Description] LIKE '0%')
OR ([ph].[LastName] IN ('n/a', 'N/A', ' ')) OR ([ph].[LastName] LIKE '0%')
Can anyone tell me the query plzzz
Thanks