Hi I am trying to remove the delimiter along with the value(s) in the sku
column. Any help would be appreciated!
TABLE
| container | sku | qty |
| ------------ | ------------ | ------------ |
| YMLU1234567 | 534164 | 1877 |
| YMLU1234567 | 987876 | 554 |
| YMLU1234567 | 987876-1 | 91 |
| YMLU1234567 | 987877 | 841 |
| YMLU1234567 | 987877-1 | 106 |
Current code
SELECT
[so].[OrderGroup] as container,
REVERSE(LEFT(REVERSE([so].[CustomerOrderNumber]),
CHARINDEX(' ', REVERSE([so].[CustomerOrderNumber]) + ' ') - 1)) AS sku,
sum([so].[QtyShipped]) as AllocatedQty
FROM [server].[dbo].[table] as so
WHERE [so].Status <> 0
AND [so].CustomerName ='alpha'
AND [so].[OrderGroup] ='YMLU1234567'
GROUP BY [so].[OrderGroup], REVERSE(LEFT(REVERSE([so].[CustomerOrderNumber]),
CHARINDEX(' ', REVERSE([so].[CustomerOrderNumber]) + ' ') - 1))
1条答案
按热度按时间kq0g1dla1#
Please try the following solution.
All the work is done in the
CROSS APPLY
. It outputs a clean sku.SQL
Output