We help IT Professionals succeed at work.

SQL Insert into one table from another

Medium Priority
512 Views
Last Modified: 2012-05-11
I need select the RecID field from one table then do an insert into another table fore each row that was found.  Any examples of that?

My select will be:
Select RecID from Meta where username = 'jdoe'

I want to loop through those then do this insert:
Insert into Publishers (fkRecID, PRO_Name) values (RecID_From_Loop, 'XYZ')
Comment
Watch Question

Commented:
INSERT INTO Publishers (fkRecID, PRO_Name)
     VALUES ( (SELECT RecID FROM Meta WHERE username = 'jdoe'), 'XYZ')
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Ephraim WangoyaSoftware Engineer
CERTIFIED EXPERT

Commented:


Insert into Publishers (fkRecID, PRO_Name)
select RecID_From_Loop, 'XYZ'
from Meta where username = 'jdoe'
Aaron TomoskyDirector, SD-WAN Solutions
CERTIFIED EXPERT

Commented:
I think ewangoya is correct. No "values" when using an insert select.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.