I have the following query:
The result set is similar to:
ticket_id truck_id ship_date
100001 241 2004-05-01
100342 241 2004-05-01
100277 241 2004-05-01
100098 276 2004-05-01
100303 276 2004-05-01
I need to make a running total field that has the following logic:
[tt]DECLARE @runningtotal int
SET @runningtotal = 1
IF t.status_id <> 10 and
ship_date = ship_date while truck_id = truck_id
THEN @runningtotal = @runningtotal + 1[/tt]
Upon the change of the truck_id I need to start the count over and the count must also start over at the change of the ship_date.
...so the result set will yield:
ticket_id truck_id ship_date rt
100001 241 2004-05-01 1
100342 241 2004-05-01 2
100277 241 2004-05-01 3
100098 276 2004-05-01 1
100303 276 2004-05-01 2
Thanks in advance for any help.
Regards,
Krickles | 1.6180
Code:
SELECT t.ticket_id, t.truck_id, co.ship_date
FROM ticket t
INNER JOIN customer_order co on co.customer_order_id = t.customer_order_id
INNER JOIN truck tr on tr.truck_id = t.truck_id
ORDER BY co.ship_date, t.truck_id
The result set is similar to:
ticket_id truck_id ship_date
100001 241 2004-05-01
100342 241 2004-05-01
100277 241 2004-05-01
100098 276 2004-05-01
100303 276 2004-05-01
I need to make a running total field that has the following logic:
[tt]DECLARE @runningtotal int
SET @runningtotal = 1
IF t.status_id <> 10 and
ship_date = ship_date while truck_id = truck_id
THEN @runningtotal = @runningtotal + 1[/tt]
Upon the change of the truck_id I need to start the count over and the count must also start over at the change of the ship_date.
...so the result set will yield:
ticket_id truck_id ship_date rt
100001 241 2004-05-01 1
100342 241 2004-05-01 2
100277 241 2004-05-01 3
100098 276 2004-05-01 1
100303 276 2004-05-01 2
Thanks in advance for any help.
Regards,
Krickles | 1.6180