mike13
Posting Yak Master
219 Posts |
Posted - 2013-01-07 : 13:09:27
|
Hi All,I'm trying to split a order into difrent orders based on pack location (Packid)DECLARE @counter AS INT SELECT T_Product_Option.PackID FROM T_Order_Detail INNER JOIN T_Product_Option ON T_Order_Detail.OptionID = T_Product_Option.id WHERE (T_Order_Detail.OrderID = 552935) and (NOT (dbo.T_Product_Option.id IN (SELECT optionid FROM dbo.T_Product_Free))) GROUP BY T_Product_Option.PackID SELECT @counter=@@ROWCOUNT IF @counter>1 -- I Need to loop thru this part for each group of packid INSERT INTO T_Order_Main (CustomerID, Orderdate, IP, Orderstatus, SiteID, CouponID) SELECT CustomerID, Orderdate, IP, Orderstatus, SiteID, CouponID FROM T_Order_Main AS T_Order_Main_1WHERE orderid=@orderidINSERT INTO T_Order_Ship (OrderID, shipping, payment, referid, remark, packaging)SELECT @@identity, shipping, payment, referid, remark, packagingFROM T_Order_Ship AS T_Order_Ship_1WHERE orderid=@orderidINSERT INTO T_Order_Remark (orderid, Remarkid, remarktxt)SELECT @@identity, Remarkid, remarktxt + 'Splited From: ' + @orderidFROM T_Order_Remark AS T_Order_Remark_1 WHERE orderid=@orderid -- I Need to do a SUB loop for each product in from the packid INSERT INTO T_Order_Detail (OrderID, ProductID, OptionID, Quantity, Cost, Discount)SELECT @@identity, ProductID, OptionID, Quantity, Cost, DiscountFROM T_Order_Detail AS T_Order_Detail_1WHERE orderid=@orderid |
|