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

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

mimuk
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

P2:2:Y:Kitchen
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,

Mim

gbritton
Flowing Fount of Yak Knowledge

1176 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

mimuk
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

gbritton
Flowing Fount of Yak Knowledge

1176 Posts

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

ScottPletcher
Constraint Violating Yak Guru

USA
412 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  
 New 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.08 seconds. Powered By: Snitz Forums 2000