I need to loop through table Organisation and insert new record in User and based on the newly created userid I need to insert into UserProductMapping,UserGroups tables
Select Code,Organisationid from organisation
INSERT INTO User(userlogin,Organisationid,emailaddress,username,userpassword)
VALUES('AGT'+ Code, organisationid,'test@gmail.com','User'+ Code,'123')
INSERT INTO UserProductMapping (UserID, ProductID) VALUES (@userid, '11')
INSERT INTO UserProductMapping (UserID, ProductID) VALUES (@userid, '22')
INSERT INTO UserProductMapping (UserID, ProductID) VALUES (@userid, '33')
INSERT INTO UserProductMapping (UserID, ProductID) VALUES (@userid, '44')
INSERT INTO UserProductMapping (UserID, ProductID) VALUES (@userid, '55')
INSERT UserGroups values (@userid, 1)
INSERT UserGroups values (@userid, 3)
I need to dynamically pass the Organisationid and Code to the User table to loop through and insert new record in user after inerting user details I have to use userid to insert into child table.
in order to insert into user table based on organisation :
INSERT INTO User (userlogin, Organisationid, emailaddress, username, userpassword)
SELECT 'AGT' + Code, organisationid, 'test@gmail.com', 'User' + Code, '123'
FROM organisation;
As EzLo mentioned, output is your friend for retrieving identity values inserted: