I have the below code that is returning the order that zip codes are visited. I am able to return the zip codes correctly, but in order to make the data more user friendly I have added a dash(-) between the zip codes.
The problem comes from the fact that I cannot figure out how to eliminate the dashes for rows that only have 2 or 3 zip codes.
SELECT
[Qry_Zip Stop Sequence].[Load ID],
[1] AS [Stop 1], [2] AS [Stop 2], [3] AS [Stop 3],
[4] AS [Stop 4],
TMS_Load.[Shipped Date/Time],
CONCAT(ISNULL([1], ''), '-', ISNULL([2], ''), '-', ISNULL([3], ''), '-', ISNULL([4], '')) AS [Zip to Zip w Stops]
FROM
(SELECT
[Load ID], [Sequence], [Stop Zip]
FROM
TMS_Load_Stops) ls
PIVOT
(MIN([Stop Zip])
FOR [Sequence] IN ([1], [2], [3], [4])) AS [Qry_Zip Stop Sequence]
INNER JOIN
[TMS_Load] ON [TMS_Load].[Load ID] = [Qry_Zip Stop Sequence].[Load ID];
I would like the results to show only show the dashes between valid zip codes.
78052-45050-45201 or
73350-45220 or
84009-48009-14452 or
36521-38222-87745-95123 or
73368 or
12789-35789
