Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Loop help
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mike13
Posting Yak Master

Netherlands
219 Posts

Posted - 01/07/2013 :  13:09:27  Show Profile  Click to see mike13's MSN Messenger address  Reply with Quote
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_1
WHERE orderid=@orderid

INSERT INTO T_Order_Ship
(OrderID, shipping, payment, referid, remark, packaging)
SELECT @@identity, shipping, payment, referid, remark, packaging
FROM T_Order_Ship AS T_Order_Ship_1
WHERE orderid=@orderid

INSERT INTO T_Order_Remark
(orderid, Remarkid, remarktxt)
SELECT @@identity, Remarkid, remarktxt + 'Splited From: ' + @orderid
FROM 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, Discount
FROM T_Order_Detail AS T_Order_Detail_1
WHERE orderid=@orderid


visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 01/07/2013 :  23:46:28  Show Profile  Reply with Quote
how do you relate packid to other tables? can you explain with some sample data?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000