question

rabishakeel-4464 avatar image
0 Votes"
rabishakeel-4464 asked LiHongMSFT-3908 commented

How to insert multiple row into a table?

I am inserting data into Probale, Then I want to insert 10 rows (depend on Qty) get insert into #tbl_PckDetail,Prdno value will be same

CREATE TABLE #Probale (prdno INT,orderno int,CodeItem int,Weigth int,prdqty int,EntryDate date,DelID int,PID int)

    INSERT INTO #Probale VALUES(10000,15,10,270,1,'2020-10-21',null,111) 
  Create table #tbl_PckDetail (DID int, prdno int,Qty int ,delid int)

191557-190242-image.png


sql-server-generalsql-server-transact-sql
190242-image.png (13.7 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @rabishakeel-4464
Is there any update of this issue?
If the answer is not working or helpful, please share with us your confusion or more details about this issue.

Best regards,
LiHong

0 Votes 0 ·

1 Answer

LiHongMSFT-3908 avatar image
0 Votes"
LiHongMSFT-3908 answered

Hi @rabishakeel-4464
Check this:

 CREATE TABLE #Probale (prdno INT,orderno int,CodeItem int,Weigth int,prdqty int,EntryDate date,DelID int,PID int) 
 INSERT INTO #Probale VALUES(10000,15,10,270,1,'2020-10-21',null,111) 
 Create table #tbl_PckDetail (DID int, prdno int,Qty int ,delid int)
    
 ;WITH CTE AS
 (
  SELECT 1 AS DID,Prdno,prdqty AS QTY,DelID
  FROM #Probale
  WHERE prdqty =1
  UNION ALL
  SELECT DID+1 AS DID,Prdno,QTY,DelID
  FROM CTE
  WHERE DID<10
 )
 INSERT INTO #tbl_PckDetail 
 SELECT * FROM CTE
    
 SELECT * FROM #tbl_PckDetail

You can also find solutions from other experts in this thread:Insert Multiple Row into Table

Best regards,
LiHong


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.