user1824963
user1824963

Reputation: 101

User values from select statement and insert into DB

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: table image

Any help is appreciated.

Upvotes: 1

Views: 102

Answers (1)

zimdanen
zimdanen

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

Related Questions