Reputation: 151
I have a 4 tables. One of the tables we are going to be inserting data into (Table A). Table A is going to receive misc data from Table B, C, D and also some unknown variable parameter data.
How do I set up the INSERT with a SELECT with also receiving parameters?
Upvotes: 2
Views: 6538
Reputation: 30711
Something like this:
DECLARE @a int, @b int
SET @a = 5
SET @b = 7
INSERT INTO TableA(Column1, Column2)
SELECT SomeOtherColumn, @a
FROM TableB
UNION
SELECT YetAnotherColumn, @b
FROM TableC
Upvotes: 0
Reputation: 85126
Something like this?
Insert INTO TableA (col1, col2,col3,col4)
SELECT b.col1, c.col2, d.col3, @myparam
FROM TableB as b
INNER JOIN TableC as c
ON b.id = c.id
INNER JOIN TableD as d
on c.id = d.id
Upvotes: 4