SQL - Conditional merge join

  • I want to add a condition in the joining columns part of the merge statement like this :

    Merge dbo.tblDest as target

    using

    (select ...) as source

    on target.EmpID =  source.EmpID

    and target.AwardID = source.AwardID  --this second condition I want to add only if the source.AwardID is not null. How to do that pls advise.

    something like this -

    on target.tblEmpID =  source.tblEmpID

    and case when source.tblAwardID is not null then target.tblAwardID = source.tblAwardID end --but this syntax doesnt work .

     

    • This topic was modified 1 month ago by SQL Bee.
  • Maybe

    (target.tblAwardID =  source.tblAwardID or  source.tblAwardID is null)

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply