Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9238987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:53:07+00:00 2026-06-18T07:53:07+00:00

I’m working with SQL on Microsoft SQL Server Management Studio 2008. In a nut

  • 0

I’m working with SQL on Microsoft SQL Server Management Studio 2008.

In a nut shell, I’m receiving data on coordinates as 115949833 and I need it to output as 115.949833 because I need to be able to calculate the mileage between the latitude and longitude coordinates. Both the longitude and latitude values are saved as integers with no decimal places. I was trying to change it to a string so I could use a substring to concatenate and convert it into a floating point. I’ve already figured out the formula for the mileage between lat and long values but its not accurate because of the issue with the decimal point.

Here’s the code I used for the longitude:

Cast(substring(str(longitude,1,not null),1,3)+'.'+substring(str(longitude,4,not null),4,9) as float) as longitude

It keeps telling me I have an incorrect syntax near CAST.

I’ve been doing a lot of research and still couldn’t find an exact way of performing this task. If anyone could provide any feedback, tips, help, etc. It would be greatly appreciated. Thanks.

***EDIT: I need the entire column named “Longitude” to be converted into a floating point or to somehow display a decimal after the 3rd character and the entire column named “Latitude” to display a decimal after the 2nd character.

So for example right now my columns show:

Latitude Longitude
36158500 115949833
36340000 115914667
36153488 115944875

and I need it to look like this:

Latitude Longitude
36.158500 115.949833
36.340000 115.914667
36.153488 115.944875

*EDIT*
So using Tim Lehner’s Answer, I’ve used my code and implemented his answer, but now I need to figure out how to get it to show the mileage using the new Latitude and Longitude columns… I created a few temp table’s to store the information I wanted in based on specific radio_name’s but I can’t pull the info from those temp tables using Tim’s Answer.

Here’s the code I’m using:
USE [system]
GO
With CTE as
(SELECT * FROM AVL
WHERE (DATE_TIME between ’01/30/2013 00:00:00′ AND
’01/30/2013 23:59:59′) AND radio_name = ‘MAS7’)
CTE2 as
(select *,row_number() over(partition by Vehicle_ID order by Date_Time) as RN
FROM CTE)

      SELECT *, sqrt((69.1*(previous.Latitude - next.Latitude))*
     (69.1*(previous.Latitude-next.Latitude)) + 
     (69.1*(previous.Longitude-next.Longitude)) *
     cos(next.Latitude/57.3) * (69.1*(previous.longitude-next.Longitude)) *
     cos(next.Latitude/57.3)) as Miles

    From CTE2 as Previous
    Join CTE2 as Next
    On previous.Vehicle_ID = Next.Vehicle_ID
    AND Previous.RN = 
    Next.RN - 1
    SELECT CAST(Latitude / 1000000.0 as decimal(10, 6)) as Latitude, 
    cast(Longitude / 1000000.0 as decimal(10, 6)) as Longitude
    from AVL

The actual code itself does work and function properly but the mileage calculation is using the original whole latitude/longitude numbers and not the updated numbers that have the decimal point.

I tried plugging in CTE2 in the last statement instead of AVL and it says it’s an invalid object name. Any pointers or tips?…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:53:08+00:00Added an answer on June 18, 2026 at 7:53 am

    I like to use datatypes to my advantage:

    select 115949833 / 1000000.0
    -- returns 115.949833000
    

    You can then round/truncate to your spec.

    Adding the decimal point to the divisor will promote the output of this operation to numeric per the rules of datatype precedence.

    UPDATE

    Per your test data, you might use a query like this:

    select cast(Latitude / 1000000.0 as decimal(10, 6)) as Latitude
      , cast(Longitude / 1000000.0 as decimal(10, 6)) as Longitude
    from MyTable
    
    /*
    Returns:
    Latitude    Longitude
    36.158500   115.949833
    36.340000   115.914667
    36.153488   115.944875
    */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I have thousands of HTML files to process using Groovy/Java and I need to
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.