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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Split the string using dot

Author  Topic 

rsmohankumar
Starting Member

11 Posts

Posted - 2015-04-08 : 14:01:50
Hi,

I have data like 'US.USA.Florida.Miami'. I need to split this string as below

Continent Country State Location
=========== ========= ========= ============
US USA Florida Miami

Delimiter is dot '.'. Kindly let me know is there any chance to do this using the
sql server built in functions.

Thanks in advance.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-04-08 : 14:03:42
Yes you can use the PARSENAME function.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

rsmohankumar
Starting Member

11 Posts

Posted - 2015-04-09 : 01:29:42
Hi Tara,

I have data like this 'US.USA.Florida.Miami.'. I missed the dot at the end. If we have the dot at the end,PARSENAME function is not working. Is there any other built in function we can handle this.
Go to Top of Page

rsmohankumar
Starting Member

11 Posts

Posted - 2015-04-09 : 02:57:22
I got the output using your inputs.
PARSENAME(STUFF('US.USA.FLORIDA.MIAMI.',LEN('US.USA.FLORIDA.MIAMI.'),LEN('US.USA.FLORIDA.MIAMI.'),''),2)

Thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2015-04-10 : 08:06:15
or

PARSENAME(LEFT('US.USA.FLORIDA.MIAMI.',LEN('US.USA.FLORIDA.MIAMI.')-1)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -