Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I have a table (A) that needs a corresponding row in (B). Is there a way to loop through (A), Insert into (B) and Get (B.UniqueId)? Its imported data hence copying some of the fields over
UPDATE B SET ParentID =(INSERT INTO A(Name,Date,Details) SELECT Name,Date,Detail FROM B)
Any ideas greatly recieved :)
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2009-07-15 : 14:16:48
you need to do it in two steps
INSERT INTO A(Name,Date,Details) SELECT Name,Date,Detail FROM BUPDATE bSET b.ParentID=a.UniqueIdFROM TableB bINNER JOIN TableA aON a.Name = b.Name AND a.Date=b.DateAND a.Detail=b.Detail