简体   繁体   中英

copy single/multiple records from a query and update the same in the queried table

Ok, I have a query that will bring 1 or more records I know how to update but I need to insert the same PN and Keyvalue to a temp table so I can revert my update at a later time.

I could create a table var and put the records in it then update from the table var and do my insert from the table var.

Is that the most efficient method?

declare @tempTable table(PART nvarchar(30), [ENTDATE] [datetime])
declare @entdate datetime
set @entdate = getdate()

insert into @tempTable(PIW_PART, PIW_ENTDATE)
select mfgp.part, @entdate from [dbo].[PARTMFGS] mfgp
inner join PARTS p on mfgp.MFP_PART = par_code
where mfgp.MFP_MANUFACTPART = 'ddd1' and mfgp.MFP_MANUFACTURER = 'udy'
and (PREVENTREORDERS = '+')

update rp
set PREVENTREORDERS  = '-',
UPDATED = getdate(),
UPDATEDBY = 'IONUSER'
from PARTS rp
inner join @tempTable tt on tt.PART collate Latin1_General_BIN = code

--@tempTable
insert into PARTS_temp (PIW_PART, PIW_ENTDATE)
select * from @tempTable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM