Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi All,

I have a table which have 10 columns. I have to insert data for that table. I have some insert statements. first insert statement insert data for first 3 rows from one source. Now I want to insert data for next columns in same row using another insert statements from different source.
These insert queries runs daily for table Order_Warehouse_Status, so we will have 1 row for daily transaction.

Ex. Table Order_Warehouse_Status have 10 columns like Printed_PPS_Shipment,Printed_Shipment_Lines,Printed_Unit, Picking_Scheduled_Orders, Picking_Scheduled_Lines, Picking_Scheduled_Units, Pick_Complete_Orders, Pick_Complete_Lines, Pick_Complete_Units. below 1st query insert data in first 3 columns. 2nd query should insert data for next column in same row. How to achieve this?

--1st Query
SQL
insert into Order_Warehouse_Status (Date, Printed_PPS_Shipment,Printed_Shipment_Lines,Printed_Unit) SELECT Getdate(),count(v_c_ship_ship_id) as Printed_PPS_Shipment, count(ship_l_id) as Printed_Shipment_Lines, count(allocated_qty) as Printed_Unit FROM [STG_WMS_Status_PPS_Line_QTY] where CONVERT(DATE,Inserted_date )=CONVERT(DATE,Getdate()) and shipment_status=2


--2nd query

SQL
insert into Order_Warehouse_Status (Date, Picking_Scheduled_Orders, Picking_Scheduled_Lines, Picking_Scheduled_Units) SELECT Getdate(), count(v_c_ship_ship_id) as Picking_Scheduled_Orders, count(ship_l_id) as Picking_Scheduled_Lines, count(allocated_qty) as Picking_Scheduled_Units FROM [STG_Closed_Received] where CONVERT(DATE,Inserted_date )=CONVERT(DATE,Getdate()) and shipment_status=7


Thanks in advance
Posted
Updated 11-May-15 18:56pm
v6
Comments
Mehdi Gholam 12-May-15 0:17am    
You don't INSERT into an existing row you use UPDATE.
virusstorm 12-May-15 11:08am    
You might want to look at using the MERGE statement, that might help you help.

1 solution

You can only update the row once it is inserted. Get the inserted identity value. Update the necessery columns based on the identity value in second query.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900