Emmanuel Ogoma
Emmanuel Ogoma

Reputation: 582

SQL SERVER How do you insert multiple rows using Insert into select statement

This is my query, the commented line is what i want to insert

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'; 

Upvotes: 0

Views: 82

Answers (3)

Mansoor
Mansoor

Reputation: 4192

 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')

Upvotes: 0

anakpanti
anakpanti

Reputation: 329

Try this code:

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')

Upvotes: 3

Krish
Krish

Reputation: 39

select ItemCode,getDate(),Description,PostingDocid,'New Ref',Qty,Price,'uid','bc','sc' 
into tbl_StockTransactions
from tbl_PostingDetailsStock 
where PostingReference='A000275'

Upvotes: 0

Related Questions