- I have the following table containing n bins in a warehouse and their coordinate points on a map.
- I would like to find the distance between every point in the list.
- I have attempted to use a
pivot
,cross apply
,cross join
, etc and ultimately get nowhere close to the intended result (typically get an error) so I will refrain from posting my code here.. - Below is my sample data and my desired output.
- ...and once found, how can I insert the shortest path/route into a new temporary-table?
Sample Data:
BinCoord | BinNumb |
---|---|
(27,1) | S |
(18,2) | D1 |
(24,2) | B1 |
(15,23) | E20 |
Desired output:
(Distances are placeholders, not actual values). I'm not too bothered about how the BinPath
is represented: e.g. a To and From column would also work fine.
Distance | BinPath |
---|---|
3.32 | S-D1 |
5.54 | D1-B1 |
7.62 | B1-E20 |
2.23 | D1-E20 |
I would assume this needs to be in some sort of loop or maybe is achievable in a pivot with some dynamic SQL. My apologies for not having a better attempted path.
Here is what I tried:
It takes my sample data and apparently does nothing because I don't understand what I need to do. My aim was to create a matrix and then do some sort of loop or cross apply
to find distances between all points in the matrix.
SELECT
D1.[BinCoord],
D1.[BinNum]
FROM
##Djik3 D1
CROSS JOIN ##Djik3 D2
WHERE
D1.BinCoord = D2.BinCoord
AND
D1.BinNum = D2.BinNum