Can someone suggest the best method or a Stored Proc that allows updating a directory.
Say we receive a new list of barristers for a chambers every 2 months. We need to
- Insert new records where they don't already exist - Based on First name, Surname
- If they exist then update certain fields that may be blank e.g. phone number
- Set any that weren't on the list to Live = 'N'
Generally getting lists in excel or an email, so having to clean up data.
select top 0 * into #temp from *table*
Insert new data #temp
If not exists (select * from *table* where forename = 'X' and surname = 'Y' and ChambersID = 12) Insert into *table* (Title, forename, surname, yearofcall, ChambersID) values ('Mr','X', 'Y', 2018, 35) else update *table* set yearofcall = 2018 where forename = 'x' and surname = 'Y' and ChambersID = 12
This seems to work. Then i do another query.
If not exists (select * from #temp where ChambersID = 12) update *table* set live = 'N' where ChambersID = 35
but long winded as have to build half query in excel... much prefer a stored proc where i can pass forename, surname and chambersid