I was looking at posts in SQL Server programming forum with the most stars, and I stumbled upon this one.
thread183-1197121 (I know, it's old, but I'm new...)
I was able to solve it, and I am now trying to get my head around how to figure out the shortest route that would have one visit all 50 capitals.
I first tried to get the closest other capital to each capital, and was able to do that with a very ugly query, but this latest question I have has got me very puzzled.
If anyone would care to join me in this undertaking, I'm all ears. Of course I am open to any tips you MVP's out there would be willing to offer!
Hope this gets at least a little interest,
Alex
PS - here is the code I used to get the closest capitals, if anyone is interested. I had to eliminate the rounding because a few had matching rounded values.
It's a magical time of year in Philadelphia. Eagles training camp marks the end of another brutal season of complaining about the Phillies.
thread183-1197121 (I know, it's old, but I'm new...)
I was able to solve it, and I am now trying to get my head around how to figure out the shortest route that would have one visit all 50 capitals.
I first tried to get the closest other capital to each capital, and was able to do that with a very ugly query, but this latest question I have has got me very puzzled.
If anyone would care to join me in this undertaking, I'm all ears. Of course I am open to any tips you MVP's out there would be willing to offer!
Hope this gets at least a little interest,
Alex
PS - here is the code I used to get the closest capitals, if anyone is interested. I had to eliminate the rounding because a few had matching rounded values.
Code:
[COLOR=white]
select x.FromCapital, c.ToCapital, x.MDIST
From
(SELECT
c.FromCapital, min(c.Distance) as MDIST
from
(SELECT
a.Capital +', ' + a.State AS FromCapital,
b.Capital +', ' + b.State AS ToCapital,
convert(int,dbo.fnCalculateDistance(a.longitude, a.latitude, b.longitude, b.latitude)
*5) as DISTANCE
from StateCapitals a, StateCapitals b
where a.Capital <> b.Capital) c GROUP BY c.FromCapital)
x
INNER JOIN
(SELECT
a.Capital +', ' + a.State AS FromCapital,
b.Capital +', ' + b.State AS ToCapital,
convert(int,dbo.fnCalculateDistance(a.longitude, a.latitude, b.longitude, b.latitude)
*5) as DISTANCE
from StateCapitals a, StateCapitals b
where a.Capital <> b.Capital) c
ON
x.FromCapital = c.FromCapital and x.MDIST = c.Distance
group by x.FromCapital, c.ToCapital, x.MDist
order by ltrim(right(x.FromCapital, charindex(',',reverse(x.FromCapital))-1)), x.MDIST
[/color]
It's a magical time of year in Philadelphia. Eagles training camp marks the end of another brutal season of complaining about the Phillies.