Need Store Procedure

Analyst_SQL 3,576 Reputation points
2022-11-15T10:14:27.58+00:00

i have data in below table

Create table #tbl_ContD  (D_ID int,CID int,C_Weight int, I_ID int)  
  
insert into #tbl_ContD values (10001 ,20153,200,54)  
  
insert into #tbl_ContD values (10022 ,20153,300,null)  
  
insert into #tbl_ContD values (10033 ,20153,400,15)  
  

i want to filter record using below query .

select Top(1) D_ID,C_weight   from #tbl_ContD where CID=20153 and I_ID is null  

then insert above record D_ID and C_Weight into #tbl_Issuance_Rags like below

Create table #tbl_Issuance_Rags (R_ID int,D_ID int,R_Weight int,R_Date date,R_QTY int,E_Date date,R_Belt varchar)  
  
  
insert into #tbl_Issuance_Rags values (1111,10022,300,'2022-11-15',1,'2022-11-15','G')  
Developer technologies Transact-SQL
SQL Server Other
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.5K Reputation points
    2022-11-15T10:59:33.857+00:00

    Check an interpretation:

    insert #tbl_Issuance_Rags(R_ID, D_ID, R_Weight, R_Date, R_QTY, E_Date, R_Belt)  
    select Top(1) 1111, D_ID, C_Weight, getdate(), 1, getdate(), 'G'  
    from #tbl_ContD   
    where CID = 20153 and I_ID is null  
    

    If it works, define a stored procedure.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.