Designware
Technical User
- Sep 24, 2002
- 202
Hi,
I'm having difficulty selecting and dynamically updating rows in a single table, based upon the records having more than one shipto_id in any given order.
If I have data such as:
ORDER_NO SHIPTO_ID
1 20
1 21
1 21
2 22
2 22
2 23
I would like to update the shipto_id to whatever shipto_id that comes first. So the data would be changed to:
ORDER_NO SHIPTO_ID
1 20
1 20
1 20
2 22
2 22
2 22
I have a query that identifies all the unique order_no / shipto_id combinations, but only returns a single row for each unique combination.
SELECT ORDER_NO, SHIPTO_ID
FROM IMPL
WHERE ORDER_NO > 1
GROUP BY ORDER_NO, SHIPTO_ID
HAVING (COUNT (DISTINCT SHIPTO_ID)) > 1
If I declare a @variable in the script, how can I set / reset it to equal the first shipto_id that appears at the beginning of the group? Or are there other ways I can dynamically update the shipto_id appropriately?
Thanks!
I'm having difficulty selecting and dynamically updating rows in a single table, based upon the records having more than one shipto_id in any given order.
If I have data such as:
ORDER_NO SHIPTO_ID
1 20
1 21
1 21
2 22
2 22
2 23
I would like to update the shipto_id to whatever shipto_id that comes first. So the data would be changed to:
ORDER_NO SHIPTO_ID
1 20
1 20
1 20
2 22
2 22
2 22
I have a query that identifies all the unique order_no / shipto_id combinations, but only returns a single row for each unique combination.
SELECT ORDER_NO, SHIPTO_ID
FROM IMPL
WHERE ORDER_NO > 1
GROUP BY ORDER_NO, SHIPTO_ID
HAVING (COUNT (DISTINCT SHIPTO_ID)) > 1
If I declare a @variable in the script, how can I set / reset it to equal the first shipto_id that appears at the beginning of the group? Or are there other ways I can dynamically update the shipto_id appropriately?
Thanks!