0

I have a table like this

AccountID      GEO

CT-2000       9.9582925,-84.19607

I want to separate the comma delimited string into two columns

AccountID      LAT         LONG 

CT-2000       9.9582925    -84.19607
RamPrakash
  • 1,687
  • 3
  • 20
  • 25
Luis Rojas
  • 11
  • 3

1 Answers1

1

You may try with the next approach, using LEFT(), RIGHT(), LEN() and CHARINDEX() functions:

Table:

CREATE TABLE Data (
   AccountID varchar(7),      
   GEO varchar(50)
)
INSERT INTO Data
   (AccountID, GEO)
VALUES
   ('CT-2000', '9.9582925,-84.19607')

Statement:

SELECT 
   AccountID,
   LEFT(GEO, CHARINDEX(',', GEO) - 1) AS Lat,
   RIGHT(GEO, LEN(GEO) - CHARINDEX(',', GEO)) AS Long
FROM Data   

Result:

AccountID   Lat         Long
CT-2000     9.9582925   -84.19607
Zhorov
  • 28,486
  • 6
  • 27
  • 52