Reputation: 1931
I need to loop through table Organisation and insert new record in User table
Select Code,Organisationid from organisation
INSERT INTO User(userlogin,Organisationid,emailaddress,username,userpassword)
VALUES('AGT'+ Code, organisationid,'[email protected]','User'+ Code,'123')
I need to dynamically pass the Organisationid and Code to the User table to loop through and insert new record in user.
Upvotes: 0
Views: 159
Reputation: 72165
Just use INSERT INTO ... SELECT
:
INSERT INTO User (userlogin, Organisationid, emailaddress, username, userpassword)
SELECT 'AGT' + Code, organisationid, '[email protected]', 'User' + Code, '123'
FROM organisation;
Upvotes: 3