Skip to content
Advertisement

Need to copy all fields value of specific item on table to another item in SQL Server

SQL Server database snapshot:

enter image description here

I need to copy this selected article data to another article. Need a query in SQL to solve this issue.

Advertisement

Answer

If I understand, you wan the IEDetails table to have the values for art_id = 7545 copied with a different art_id value while still retaining the original values? With the data shown, I am going to assume that the Id column is defined as an IDENTITY column

If so then this should work for you:

DECLARE @new_art_id INT
DECLARE @old_art_id INT
SET @old_art_id = 7545
SET @new_art_id = 8000

INSERT IEDetails (art_id, ProcessId, SrlNo)
SELECT @new_art_id, ProcessId, SrlId
FROM IEDetails
WHERE art_id = @old_art_id

You could change where you get the values for @old_art_id and @new_art_id by using a different query than the SET statements.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement