Reputation: 101
I am trying to create a stored procedure that will return set is results and then use these results to insert into a database, I know how do this this individually but not as a combined stored procedure:
Any help is appreciated.
Upvotes: 1
Views: 102
Reputation: 5626
Try something like this:
INSERT INTO tbl_userlist (assocuser, userID)
SELECT @id, ID
FROM tbl_login
WHERE type = 'user' and assocuser = @userid
For your edit, it looks like you want to use UNPIVOT.
Here's a basic UNPIVOT example, modified straight from the MSDN UNPIVOT example:
SELECT ID, AssocUser, UserID
FROM tbl_login
UNPIVOT
(UserID FOR Col IN
(User1, User2)
)AS unpvt;
You should be able to expand it from there.
Upvotes: 1