T-sql insert - select - with parameters
I have 4 tables. We are going to insert data into one of the tables (table A). Table A will get different data from tables B, C, D as well as some unknown variable parameter data.
How do I set up INSERT with SELECT while also getting parameters?
+2
Argyle ghost
source
to share
2 answers
Something like that?
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
+4
Abe miessler
source
to share
Something like that:
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
0
Bridge
source
to share