对sql中现有行的多个Insert查询。 [英] multiple Insert query for existing row in sql.

查看:71
本文介绍了对sql中现有行的多个Insert查询。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的桌子有10列。我必须为该表插入数据。我有一些插入语句。第一个插入语句插入来自一个源的前3行的数据。现在我想使用来自不同源的另一个插入语句为同一行中的下一列插入数据。

这些插入查询每天为表Order_Warehouse_Status运行,因此我们每日事务将有1行。



Ex。表Order_Warehouse_Status有10列,如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。低于第一个查询在前3列中插入数据。第二个查询应该在同一行中插入下一列的数据。如何实现这个目标?



--1st查询

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查询





--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

推荐答案

只能在插入行后更新行。获取插入的标识值。根据第二个查询中的标识值更新necessery列。
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.


这篇关于对sql中现有行的多个Insert查询。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆