SQL Server: Update portion of Merge Statement not working -
i think i've been looking @ statement way long. can tell me why update portion of statement isn't updating? think testing or
, !=
on columns, should invoke cause updates when needed--instead, seem have unintentionally created condition ..where update never needed!
here 4 things know prior looking @ statement:
1. data in temp table #facilities populated current data multiple sources. data contains bot new (insert) , changed (update) data.
2. contents of #facilities has been verified contain data, prior executing merge statement.
3. insert portion of merge statement succeeds.
4. although update portion of statement not update changed data, statement not fail.
merge phonemaster facilitymaster using #facilities facilitynew on facilitymaster.facilityid = facilitynew.facilityid , facilitymaster.siteid = facilitynew.siteid when matched , ( facilitymaster.user__bid != facilitynew.user__bid or facilitymaster.email__baddress != facilitynew.email__baddress or facilitymaster.facility__bname != facilitynew.facility__bname or facilitymaster.division != facilitynew.division or facilitymaster.district != facilitynew.district ) update set facilitymaster.user__bid = facilitynew.user__bid, facilitymaster.email__baddress = facilitynew.email__baddress, facilitymaster.facility__bname = facilitynew.facility__bname, facilitymaster.division = facilitynew.division, facilitymaster.district = facilitynew.district when not matched insert ( user__bid, email__baddress, facility__bname, division, district, facilityid, siteid ) values ( facilitynew.user__bid, facilitynew.email__baddress, facilitynew.facility__bname, facilitynew.division, facilitynew.district, facilitynew.facilityid, facilitynew.siteid );
one thing i've noticed insert statment not populate facilityid or siteid. other suggestion make comment out 'and' clause on when matched, adding in in line @ time until fails. use merge time , fast , efficient.
Comments
Post a Comment