SQL SERVER如何使用Insert into select语句插入多行

时间:2016-11-25 08:46:30

标签: sql sql-server

这是我的查询,注释行是我要插入的内容

insert into tbl_StockTransactions(ItemCode,TransactionDate,Narration,Docid,ReferenceNo,Qty,Price,UserId,BranchCode,StaffCode) select ItemCode,getDate(),Description,PostingDocid,'New Ref',Qty,Price,'uid','bc','sc' from tbl_PostingDetailsStock where PostingReference='A000275'
--select ItemCode,getDate(),Description,PostingDocid,'New Ref',Qty,Price,'uid','bc','sc' from tbl_PostingDetailsStock where PostingReference='A000276'; 

3 个答案:

答案 0 :(得分:3)

试试这段代码:

insert into tbl_StockTransactions(
    ItemCode, TransactionDate, Narration, Docid, ReferenceNo, Qty,
    Price, UserId, BranchCode, StaffCode
)

SELECT ItemCode, getDate(), Description, PostingDocid, 'New Ref', Qty, 
    Price, 'uid', 'bc', 'sc' 
FROM tbl_PostingDetailsStock 
WHERE PostingReference IN ('A000275','A000276')

答案 1 :(得分:0)

 insert into tbl_StockTransactions(ItemCode,TransactionDate,Narration
 ,Docid,ReferenceNo,Qty,Price,UserId,BranchCode,StaffCode)
 select ItemCode,getDate(),Description,PostingDocid,'New Ref',Qty,Price,'uid','bc','sc' from tbl_PostingDetailsStock
 where PostingReference IN ('A000275','A000276')

答案 2 :(得分:0)

df = sqlContext.read.json("hdfs://ip:port/user/ABC/examples/src/main/resources/people.json")