you could do it set based with the wonderful command MERGEsomething like thisMERGE facpricelist AS targetUSING ( SELECT ltrim(rtrim(partnumber)) Part, [pdfurl] FROM ordsys.dbo.[pak-web] ) AS source (Part, datasheet) ON (target.Part = source.Part) WHEN MATCHED THEN UPDATE SET part = source.part, datasheet=source.datasheetWHEN NOT MATCHED THEN INSERT (mfg, Part, datasheet, webdatadate) VALUES ('PAK', source.Part, source.datasheet, getdate()) OUTPUT deleted.*, $action, inserted.* INTO #MyTempTable;
caveat how big of a data do you want to move? this part SELECT ltrim(rtrim(partnumber)) Part, [pdfurl] FROM ordsys.dbo.[pak-web]
could bite youby the way you are doing a lot of whack stuff in there with ltrim rtrim you will have to implement in this MERGE. Why not put a default constraint on webdatadate instead of doing getdate()<><><><><><><><><><><><><><><><><>If you don't have the passion to help people, you have no passion