question

manuu avatar image
manuu asked

multiple Insert query for existing row in sql.

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 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 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
sql-server-2008sqlsql-server-2008-r2
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Kev Riley avatar image
Kev Riley answered
You don't want multiple inserts, you need an initial INSERT then an UPDATE. To perform the update though, you will need something that uniquely identifies the row to update - a Primary key on the Order_Warehouse_Status table?
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.