Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 PARSENAME/REPLACE or Help with Split
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

19 Posts

Posted - 07/21/2014 :  06:57:26  Show Profile  Reply with Quote
I have a MySQL Linked Server in my MS SQL Environment
I have created a SQL View to one of the MySQL tables as follows

SELECT id, contract, eventuser, eventtype, eventtext, CONVERT(varchar, eventdt, 100) AS dateactioned
FROM DATABASE...contractsaudit

The event text column contains the following data e.g

P3:1:N:Main Office

I need to split the data into multiple values (always 4 columns in that order) i.e
P3:1:N:Main Office would be

Product | Amount | Swapped | Location
P3 | 1 | N | Main Office
P2 | 2 | Y | Kitchen

Please can someone help?

Many thanks,


Flowing Fount of Yak Knowledge

2780 Posts

Posted - 07/21/2014 :  08:09:51  Show Profile  Reply with Quote
Look up documentation on charindex and substring
Go to Top of Page

Starting Member

19 Posts

Posted - 07/21/2014 :  10:54:22  Show Profile  Reply with Quote
Thanks gbritton
I ended up using parsename(replace)
PARSENAME(REPLACE(eventtext, ':', '.'), 1) AS product, PARSENAME(REPLACE(eventtext, ':', '.'), 2) AS Adjustment, PARSENAME(REPLACE(eventtext, ':', '.'), 3) AS Swapped etc.
Go to Top of Page

Flowing Fount of Yak Knowledge

2780 Posts

Posted - 07/21/2014 :  11:26:47  Show Profile  Reply with Quote
good call!
Go to Top of Page

Aged Yak Warrior

550 Posts

Posted - 07/21/2014 :  13:14:13  Show Profile  Reply with Quote
Be aware that you will get an error if a '.' ever appears in your data. Or the first time there is a fifth column of data for any reason.

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000