Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

INSERT INTO multiple select and constants

$
0
0

I am trying to do an insert using values from other tables AND constants. I have found partial answer on SO but i can't manage to finish the stored procedure. I should be doing something like

INSERTINTO table1(value1, value2, value3, value4)SELECT@value1,
    value2,
    value3,@value4 FROM table2 WHERE table2.id =@value2;-- not sure

But i must use some kind of join to get data from the 3rd table as well and i don't know how.

I have 3 tables. i want to insert like this

INSERTINTO table1(field1, field2, field3, field4)

As for values

field1 =@field1SELECT field2_type FROM table2 WHERE field2ID =@field2 -- field2SELECT field3_type FROM table3 WHERE field3ID =@field3 -- field3
field4 =@field4

I am using SQL Server 2012

table1 looks like:

ID       int, PK
Name     varcharFunction int
Type     int
Age      int

table2 looks like:

FunctionID           int
FunctionDescription  varchar

table3 looks like:

TypeID               int
TypeDescription      varchar

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>