Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
wyerarch
Starting Member
2 Posts |
Posted - 2009-06-16 : 08:15:42
|
| Hi All,I am retrieving data from my sql db, which represents distances from customers. The problem is, each customer can register more than one address/postcode.What I am doing is looking up the logitude and latitude of the postcode, and calculating the distance from the target. What I get back is something like:ID Customer Distance1 A 21 A 52 B 62 B 19What I need is:ID Customer Distance1 A 22 B 6I.e. Out of this data, retrieve the first, closest record by distance.Does anyone know how please?Many thanks in advance.James. |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2009-06-16 : 08:18:56
|
| select id, customer, distance = min(distance)from tblgroup by id, customer==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
wyerarch
Starting Member
2 Posts |
Posted - 2009-06-16 : 09:09:55
|
| Thanks nr, that worked a treat! |
 |
|
|
|
|
|