views:

37

answers:

2

i need to insert 4 column in sql table

fist 2 column i have type remain 2 column i have to get it from another table ..how combine and insert this in single query

+2  A: 

Is this the sort of thing you are looking for...

INSERT INTO my_table_1 (col1, col2, col3, col4)
    SELECT const_1, const_2,  col7, col8
        FROM my_table_2;

where the const_1 are fixed numbers? If not, perhaps you could expand a bit on your question.

Brian Hooper
+3  A: 

You can combine an INSERT with a SELECT statement, passing your values in the select statement.

Assuming you pass the values of the first two columns using parameters @a and @b you can write

INSERT INTO TABLE Table1 (Table1Col1, Table1Col2, Table1Col3, Table1Col4)
SELECT @a, @b, Table2Col1,Table2Col2
FROM Table2
WHERE ....
Panagiotis Kanavos