I’m trying to update or insert data dependent on whether the account number is already in the existing data.
Firstly I added the new variables to those with an acocunt number already in the table using this
drop table #test1
select a.*, B.Delq_Sep12, b.Bal_Sep12, b.Queue_Sep12
into #test1
from pcd1 a
left join #pcd_sep12 b on (a.ACCOUNT_NUMBER = B.account_number)
Then I add all those records whose account number is not in test1 (created above) from #pcd_sep12 into test1
INSERT #test1
SELECT * FROM #pcd_sep12 WHERE account_number NOT IN(SELECT account_number FROM #test1)
I get the error Column name or number of supplied values does not match table definition.
I realise its because theres not the same number of fields but is there a way around this?
Why not use the MERGE (aka “upsert”) statement?
This way you don’t need a temp table or any tests: these won’t be concurrency-safe under load