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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 iterate all id and insert

Author  Topic 

magmo
Aged Yak Warrior

558 Posts

Posted - 2011-09-30 : 04:45:00
Hi

I need to iterate all ID from tableA and insert into tableB based on that ID, can someone show me how?

tableA

UID

tableB
ID, UID, NID


like this..

INSERT INTO tablea (UID,NID) VALUES (UIDfromtableA, 77)


So the UIDfromtableA is the ID that will change depending on the iteration, and the NID is a fixed value

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-30 : 04:57:54
[code]
INSERT INTO tableB (UID,NID)
SELECT UIDfromtableA, 77 FROM tableA
[/code]


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

magmo
Aged Yak Warrior

558 Posts

Posted - 2011-09-30 : 06:01:38
Great, Thanks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-30 : 06:05:08
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -