插入数据顺序来自另一个 table

insert data order by from another table

    I have 2 table first is master table second is transaction table.i want to insert data from second table into temp table .

我需要从另一个 table 插入一个 table 数据。我正在尝试编写此 sql 代码。但是这个 order by option 在插入数据时不起作用 按授予 table 的顺序从 table 插入数据。但我认为先插入拳头然后按顺序插入数据。

    here is my table syntax.


    Create table tabl_master
    (DESC_ID int IDENTITY(1,1) PRIMARY KEY,  
      SUM_DESCRIPTION nvarchar(500) 
      )

    Create table tabl1
    (PROGRESS_REPORT_BUDGETID int IDENTITY(1,1) PRIMARY KEY,  
      RFP_ID int, 
      DESC_ID int , 
      TOTAL_BUDGET decimal(18,2) 
      )


      insert into tabl_master values('1.1 Salaries-Program management staff')
      insert into tabl_master values('1.2 Salaries-Field staff, outreach workers, medical staff and other service providers')
      insert into tabl_master values('1.3 Other HR Costs')
      insert into tabl_master values('1.4 Salaries-Finance and Administration Staff')
      insert into tabl_master values('2.2 Technical Assistance related per diems/transport/other costs')
    insert into tabl_master values('2.3  Assistance related per diems/transport/other costs')

      insert into tabl1 values(101,1,2500)
    insert into tabl1 values(101,2,7500)
    insert into tabl1 values(101,3,3500)
    insert into tabl1 values(101,4,0)
    insert into tabl1 values(101,5,0)
    insert into tabl1 values(101,6,0)
    insert into tabl1 values(101,7,0)



    DECLARE @ProductTotals TABLE
    (
      srnum int, 
      PROGRESS_REPORT_BUDGETID int,
      SUM_DESCRIPTION nvarchar(550),
      RFP_ID int,
      DESC_ID int,
      GRAND_TOTAL decimal(18,3)
    )
    insert  into @ProductTotals


    SELECT   row_number() over (order by (select NULL))as srnum,               
    PROGRESS_REPORT_BUDGETID,BS.SUM_DESCRIPTION,  
      RFP_ID, PB.DESC_ID, TOTAL_BUDGET             
     FROM tabl1 PB                
      INNER JOIN tabl_master BS ON PB.DESC_ID=BS.DESC_ID               

      ORDER BY TOTAL_BUDGET  desc
       select * from @ProductTotals  

Result is coming as 

enter image description here

我期待的结果是

enter image description here

声明@ProductTotals TABLE ( srnum 整数, PROGRESS_REPORT_BUDGETID 整数, SUM_DESCRIPTION nvarchar(550), RFP_ID 整数, DESC_ID 整数, GRAND_TOTAL 十进制(18,3) ) 插入@ProductTotals

SELECT row_number() over (order by (select NULL))as srnum,
PROGRESS_REPORT_BUDGETID,SUM_DESCRIPTION,
RFP_ID, DESC_ID, TOTAL_BUDGET 来自( SELECT PROGRESS_REPORT_BUDGETID,BS.SUM_DESCRIPTION,
RFP_ID、PB.DESC_ID、TOTAL_BUDGET
FROM tabl1 PB
内连接 tabl_master BS ON PB.DESC_ID=BS.DESC_ID
其中 TOTAL_BUDGET <> 0 联合所有

select PROGRESS_REPORT_BUDGETID,BS.SUM_DESCRIPTION,
RFP_ID、PB.DESC_ID、TOTAL_BUDGET
FROM tabl1 PB
内连接 tabl_master BS ON PB.DESC_ID=BS.DESC_ID
其中 TOTAL_BUDGET = 0 ) A

   select * from @ProductTotals  

我期望的答案是这样的

enter image description here