If a patient has phone number with PrimaryPhone flag set to 1, then this phone number should be returned, otherwise first available phone, if patient doesn't have phone number return null.
There are some other conditions to be met, based on the conditions I executed the query successfully and now I need the above condition to be included in this query...
Query:
SELECT [enh].[PatientPersonID],
[enh].[MemberNumber],
[enh].[PromotionGroupID],
[enh].[EnrollmentID],
[ph].[AreaCode],
[ph].[Number],
[enh].[EnrollmentStartDate],
[enh].[EnrollmentEndDate],
[enh].[UpdateDate],
[enh].[UpdateBy]
FROM
[TCPLP].[dbo].[EnrollmentHistory] AS [enh]
JOIN [TCPLP].[dbo].[Person] AS [p] ON ([p].[PersonID]=[enh].[PatientPersonID])
JOIN [TCPLP].[dbo].[PhoneNumber] AS [ph] ON ([ph].[PersonId]=[p].[PersonID])
WHERE (([EnrollmentStatusID] IN ('12', '28', '77')) ) AND [EnrollmentStartDate] BETWEEN ('01-01-2012 00:00:00') AND ('01-08-2013 23:59:59')
Plzz Can anyone tell me what should be included for this?
Thanks
SqlTcard
There are some other conditions to be met, based on the conditions I executed the query successfully and now I need the above condition to be included in this query...
Query:
SELECT [enh].[PatientPersonID],
[enh].[MemberNumber],
[enh].[PromotionGroupID],
[enh].[EnrollmentID],
[ph].[AreaCode],
[ph].[Number],
[enh].[EnrollmentStartDate],
[enh].[EnrollmentEndDate],
[enh].[UpdateDate],
[enh].[UpdateBy]
FROM
[TCPLP].[dbo].[EnrollmentHistory] AS [enh]
JOIN [TCPLP].[dbo].[Person] AS [p] ON ([p].[PersonID]=[enh].[PatientPersonID])
JOIN [TCPLP].[dbo].[PhoneNumber] AS [ph] ON ([ph].[PersonId]=[p].[PersonID])
WHERE (([EnrollmentStatusID] IN ('12', '28', '77')) ) AND [EnrollmentStartDate] BETWEEN ('01-01-2012 00:00:00') AND ('01-08-2013 23:59:59')
Plzz Can anyone tell me what should be included for this?
Thanks
SqlTcard