SQL - Distance to nearest premise using lat/long

%3CLINGO-SUB%20id%3D%22lingo-sub-1217332%22%20slang%3D%22en-US%22%3ESQL%20-%20Distance%20to%20nearest%20premise%20using%20lat%2Flong%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1217332%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%20I%20am%20looking%20to%20create%20a%20function%20that%20i%20can%20then%20use%20on%20two%20tables.%20The%20first%20with%20UPRN%20(unique%20premise%20ref.)%2C%20Latitude%20and%20Longitude%20coordinates%20and%20type%20A.%20The%20second%20identical%20but%20of%20type%20B.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20need%20a%20function%20that%20then%20lists%2C%20for%20each%20UPRN%20in%20table%201%2C%20the%20nearest%20UPRNs%20(in%20order%20of%20distance)%20from%20table%202.%20I%20have%20looked%20at%20using%20the%20Geography%20type%20but%20am%20unsure%20how%20to%20build%20it%20into%20a%20function%20that%20i%20can%20then%20use%20on%20table%201.%20Can%20anyone%20please%20help%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1217509%22%20slang%3D%22en-US%22%3ERe%3A%20SQL%20-%20Distance%20to%20nearest%20premise%20using%20lat%2Flong%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1217509%22%20slang%3D%22en-US%22%3EHi%2C%3CBR%20%2F%3ESQL%20community%20is%20here%3A%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fsql-server%2Fct-p%2FSQL-Server%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fsql-server%2Fct-p%2FSQL-Server%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1217799%22%20slang%3D%22fr-FR%22%3ERE%3A%20SQL%20-%20Distance%20to%20nearest%20premise%20using%20lat%2Flong%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1217799%22%20slang%3D%22fr-FR%22%3EPlease%20Someone%20can%20help%20me%20here%20how%20to%20make%20a%20dynamic%20cross%20chart%20from%20a%20given%20base%20on%20excel%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1218018%22%20slang%3D%22en-US%22%3ERE%3A%20SQL%20-%20Distance%20to%20nearest%20premise%20using%20lat%2Flong%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1218018%22%20slang%3D%22en-US%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fcommunity-discussion%2Faidez-moi-svp%2Fm-p%2F1217849%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fcommunity-discussion%2Faidez-moi-svp%2Fm-p%2F1217849%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1218347%22%20slang%3D%22en-US%22%3ERe%3A%20SQL%20-%20Distance%20to%20nearest%20premise%20using%20lat%2Flong%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1218347%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F310193%22%20target%3D%22_blank%22%3E%40HotCakeX%3C%2FA%3E!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F577364%22%20target%3D%22_blank%22%3E%40Tippelschniff175%3C%2FA%3E%2C%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHello!%20You've%20posted%20your%20question%20in%20the%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FCommunity-Discussion%2Fbd-p%2FCommunityQuestions%22%20target%3D%22_blank%22%3ECommunity%20Discussion%20space%3C%2FA%3E%2C%20which%20is%20intended%20for%20discussion%20around%20the%20Tech%20Community%20website%20itself%2C%20not%20product%20questions.%20I'm%20moving%20your%20question%20to%20the%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fsql-server%2Fbd-p%2FSQL_Server%22%20target%3D%22_self%22%3ESQL%20Server%20space%3C%2FA%3E-%20please%20post%20SQL%20Server%20questions%20here%20in%20the%20future.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1218349%22%20slang%3D%22en-US%22%3ERE%3A%20SQL%20-%20Distance%20to%20nearest%20premise%20using%20lat%2Flong%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1218349%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F577563%22%20target%3D%22_blank%22%3E%40Ibrahimtoure20%3C%2FA%3E%3A%20Thanks%20for%20your%20question.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20your%20question%20is%20not%20related%20to%20this%20particular%20inquiry%20(as%20per%20our%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fcommunity-guidelines%2Fmicrosoft-tech-community-code-of-conduct%2Fm-p%2F31390%23M14%22%20target%3D%22_self%22%3Ecode%20of%20conduct%3C%2FA%3E%2C%20we%20like%20to%20stay%20on%20topic)%2C%20and%20you've%20posted%20your%20question%20in%20a%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fexcel%2Faidez-moi-svp%2Ftd-p%2F1217849%22%20target%3D%22_self%22%3Eseparate%20thread%3C%2FA%3E%2C%20could%20you%20please%20monitor%20that%20thread%20instead%20to%20help%20answer%20your%20question%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAppreciate%20that!%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Hi all, I am looking to create a function that i can then use on two tables. The first with UPRN (unique premise ref.), Latitude and Longitude coordinates and type A. The second identical but of type B.

 

I need a function that then lists, for each UPRN in table 1, the nearest UPRNs (in order of distance) from table 2. I have looked at using the Geography type but am unsure how to build it into a function that i can then use on table 1. Can anyone please help?

5 Replies
SVP Quelqu'un peut m aider ici comment faire un tableau dynamique croisé a partir d une base de donné sur excel

Thanks @HotCakeX!

 

@Tippelschniff175,  

Hello! You've posted your question in the Community Discussion space, which is intended for discussion around the Tech Community website itself, not product questions. I'm moving your question to the SQL Server space - please post SQL Server questions here in the future. 

@Ibrahimtoure20: Thanks for your question.

 

As your question is not related to this particular inquiry (as per our code of conduct, we like to stay on topic), and you've posted your question in a separate thread, could you please monitor that thread instead to help answer your question?

 

Appreciate that!