Inner Join based on column value in SQL Server 2008 -
i join 2 tables based on column value
- if
pm.servicelevelid
value 1 ornull
inner join onu.facilityid
- if
pm.servicelevelid
value 2 inner join onu.facilityserviceid
these 2 tables pm, u
have these columns:
providermessages messageid, facilityserviceid, servicelevelid, facilityid, providertypeid user_fa facilityserviceid, userfacilityid, facilityid
currently, have inner join
select distinct messageid, userfacilityid, 9 #providermessages inner join #user_fa on (#user_fa.facilityid = #providermessages.facilityid or #providermessages.facilityid null) , (#user_fa.facilityserviceid = #providermessages.facilityserviceid)
select distinct messageid, userfacilityid, 9 #providermessages join #user_fa on #providermessages.servicelevelid in (null,1,2) , ( ( #providermessages.servicelevelid in (null,1) , #user_fa.facilityid = #providermessages.facilityid) or ( providermessages.servicelevelid = 2 , #user_fa.facilityserviceid = #providermessages.facilityserviceid) )
Comments
Post a Comment