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 |
OBINNA_EKE
Posting Yak Master
234 Posts |
Posted - 2006-08-21 : 08:08:27
|
Pythagoras Theorem = d² = (x1 - x2)² + (y1 - y2)²My SQL EQUIVALENT ISselect power((x - 544400),2) + power((y - 262700),2) from tbl Is the above SQL equate to Pythagoras Theorem? , I am trying to calculate distance between a location and another (UK)SQL STUFFCREATE TABLE [dbo].[tbl] ( [PostCode] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [X] [bigint] NULL , [Y] [bigint] NULL , [Long] [money] NULL , [Lat] [money] NULL ) ON [PRIMARY]TEST DATAPCODE X Y LAT LONGE5 535000 186300 -.0530 51.5990CB4 544400 262700 .1150 52.2430If it is that easy, everybody will be doing it |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-08-21 : 08:17:30
|
Why do you think your implementation is wrong, in first place ?Harsh AthalyeIndia."Nothing is Impossible" |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-21 : 08:18:20
|
Yes, it seems correct.A note though, change money to smallmoney to save space (from 16 bytes per row to 8 bytes). No longitude nor latitude will ever be greater than 214,748 or less than -214,748.Also do the some thing for BIGINT. INT will suffice (also from 16 bytes per row to 8 bytes).And I think no postcode in the UK has more than 7 digits, right?Then your table rows has shrunk from 80 bytes to 23 bytes. This can improve your queries since now there is room for ~315 records per page instead of ~90, with a fill factor of 90%.Peter LarssonHelsingborg, Sweden |
|
|
|
|
|
|
|