开发者

Dynamically inserting multiple rows to a table

开发者 https://www.devze.com 2023-03-01 07:05 出处:网络
I need to insert multiple records into a table. The number of records depend on the result of another query. For example:

I need to insert multiple records into a table. The number of records depend on the result of another query. For example:

INSERT INTO TABLE1(colm1, colm2, colm3)
VALUES(SELECT clom1 FROM TABLE2, constant, constant)

In this query colm2, colm3 have constsnt values, the value of colm1 differs based on th开发者_JAVA技巧e ouput of TABLE2, and the number of records that are to be inserted also depend upon the number of values from TABLE2. Can someone give me a solution?


INSERT INTO Table1(colm1,colm2,colm3)
SELECT colm1,constant,constant FROM TABLE2

This should work


Try

INSERT INTO TABLE1(colm1, colm2, colm3) 
SELECT clom1, constant, constant FROM TABLE2
. . .  
0

精彩评论

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