开发者

How to insert selected value in insert statment in sqlserver [closed]

开发者 https://www.devze.com 2023-01-07 11:25 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_运维知识库 Closed 10 years ago.

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


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 ....


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号