I have 1 update SP and 2 insert SP in SQL below.
UPDATE:
update DW.dbo.table2 SET
Active_ind = 0,
expiry_date = GETDATE(),
updated_date = GETDATE()
WHERE hash_key IN (
SELECT T1.hash_key
FROM table1 T1 LEFT JOIN
DW.dbo.table2 T2 ON T1.hash_key = T2.hash_key
WHERE T1.hash_dif <> T2.hash_dif
AND T1.Active_ind = 1
) AND Active_ind = 1
INSERT 1:
insert into DW.dbo.table2
select * from table1
WHERE hash_key IN (
SELECT T1.hash_key
FROM table1 T1 LEFT JOIN
DW.dbo.table2 T2 ON T1.hash_key = T2.hash_key
WHERE T1.hash_dif <> T2.hash_dif
AND T1.Active_ind = 1)
OR DO INSERT 2:
insert into DW.dbo.table2
select * from table1
WHERE hash_key NOT IN (
SELECT T2.hash_key
FROM DW.dbo.table2 T2
WHERE T2.Active_ind = 1)
I basically want to run the UPDATE stored procedure every time. For the INSERT I want to combine them so it does the INSERT on the same hash_key with a different hash_dif OR do the insert into table2 if the hash_key from table1 doesn’t exist. Can I combine these 3 stored procedures cohesively? When I run all 3 at the same time, they run fine so can I just leave it like that?
1