Hi,
I have a single column table which looks like this:
Gaming | Austria | 47.9333, 15.1
Hebei | China | 39.8897, 115.275
This means that every row is a single string (VARCHAR) that contains some location, with the different fields separated by a pipe (|).
I would like to write a query that returns the following:
------- ---------- ---------------------------------
Gaming Austria Gaming | Austria | 47.9333, 15.1
Hebei China Hebei | China | 39.8897, 115.275
Which means I want 3 columns: for the city, for the country, and the original column.
While splitting the city is easy (combination of CHARINDEX and SUBSTRING), extracting the country seems to be more challenging. The tricky part is to know the length of the country field in the string, so it could be extracted using SUBSTRING.
I realize I might have to write a SPLIT function in T-SQL, but I'm not sure how to write one that returns the data as a record and not as a table.
Hints and/or solutions will be more than welcome.