I am in process of creating a report with the below details.
person_id,membership_id,first_name,surname,create_datetime,first_contact_date,promotion_id,promotion_description,description,heard_about_text
I am getting duplicate values for person_id with null membership_id and I am not sure why?
SELECT DISTINCT dbo.pn.person_id, dbo.pn_membership.membership_id, dbo.pn.first_name, dbo.pn.surname, dbo.pn.create_datetime, dbo.pn.first_contact_date, dbo.promo_reference.promotion_id, CASE WHEN dbo.promo.description is NULL THEN 'Promotion Not Set' ELSE dbo.promo.description END AS promotion_description, dbo.promo_sales_channel.description, dbo.memship_app_eligibility.heard_about_text FROM dbo.pn LEFT OUTER JOIN dbo.pn_membership ON dbo.pn.person_id=dbo.pn_membership.person_id LEFT OUTER JOIN dbo.promo_reference ON dbo.promo_reference.main_ref=dbo.pn.person_id LEFT OUTER JOIN dbo.promo ON dbo.promo.promotion_id=dbo.promo_reference.promotion_id LEFT OUTER JOIN dbo.promo_sales_channel ON dbo.promo_reference.sales_channel_id=dbo.promo_sales_channel.sales_channel_id LEFT OUTER JOIN dbo.memship_app_eligibility ON dbo.pn_membership.membership_id=dbo.memship_app_eligibility.membership_id WHERE dbo.pn.create_datetime >= DATEADD(Day, DATEDIFF(Day, 0, getdate()), -1) AND dbo.pn.create_datetime < DATEADD(Day, DATEDIFF(Day, 0, getdate()), 0) ORDER BY dbo.pn_membership.membership_id,dbo.pn.create_datetime desc
Sample Data:
25 NULL Pat 2014-01-14 18:06:53.407 NULL 3 No Promotion Paper NULL
25 NULL Pat 2014-01-14 18:06:53.407 NULL 3 No Promotion Phone NULL
26 525 Eri 2014-01-14 15:00:00.412 NULL 3 Promotion Phone Internet