July 29, 2010 at 3:20 am
Order Table
Seq Units Agent Filled Due
1 200 A
2 200 A
3 200 C
Order Allocations
Agent Units
A 400
C 200
July 29, 2010 at 3:49 am
Why use a cursor? Why not just do this?
DECLARE @ORDERS AS TABLE(
Seq INT,
Units INT,
Agent CHAR(1))
INSERT INTO @ORDERS
SELECT 1, 200, 'A'
UNION ALL SELECT 2, 200, 'A'
UNION ALL SELECT 3, 200, 'C'
SELECT Agent, SUM(Units) AS Units
FROM @ORDERS
GROUP BY Agent
July 29, 2010 at 6:11 am
Really appreciate your reply. I was advise to use cursors but really do not know how to use it for calculations in a Stored Procedure.
Another question - What if I have to use a running total which I then have to reduce it against the order table? In this case apply the 980 against Seq 1, 2 and 4; then show the over-allocation against Seq 4.
How can I best handle this?
--------------------------------------------------------------------
Order Table
Seq Units Agent Filled Due
1 200 A
2 200 A
3 200 C
4 500 A
Order Allocations
Agent Units
A 980
C 200
July 29, 2010 at 6:30 am
Sorry for the poor format. First time posting a question for help.:-)
July 29, 2010 at 7:24 am
61563shanti (7/29/2010)
Really appreciate your reply. I was advise to use cursors but really do not know how to use it for calculations in a Stored Procedure.
For this sort of thing, don't use a cursor. For most things, a cursor is bad.
61563shanti (7/29/2010)
Another question - What if I have to use a running total which I then have to reduce it against the order table? In this case apply the 980 against Seq 1, 2 and 4; then show the over-allocation against Seq 4.How can I best handle this?
--------------------------------------------------------------------
Order Table
Seq Units Agent Filled Due
1 200 A
2 200 A
3 200 C
4 500 A
Order Allocations
Agent Units
A 980
C 200
I don't understand where you get 980 from. . . Was that supposed to be 900? 200+200+500 for 'Agent' A? If so, it's another fairly simple answer, if not then I need to understand why before I can show you how 🙂
July 31, 2010 at 10:35 pm
Thank you.
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply