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.
Author |
Topic |
mimuk
Starting Member
19 Posts |
Posted - 2014-07-21 : 06:57:26
|
I have a MySQL Linked Server in my MS SQL EnvironmentI have created a SQL View to one of the MySQL tables as followsSELECT id, contract, eventuser, eventtype, eventtext, CONVERT(varchar, eventdt, 100) AS dateactionedFROM DATABASE...contractsaudit The event text column contains the following data e.gP2:2:Y:KitchenP3:1:N:Main OfficeI need to split the data into multiple values (always 4 columns in that order) i.eP3:1:N:Main Office would be Product | Amount | Swapped | LocationP3 | 1 | N | Main OfficeP2 | 2 | Y | KitchenPlease can someone help?Many thanks,Mim |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-07-21 : 08:09:51
|
Look up documentation on charindex and substring |
|
|
mimuk
Starting Member
19 Posts |
Posted - 2014-07-21 : 10:54:22
|
Thanks gbrittonI ended up using parsename(replace)PARSENAME(REPLACE(eventtext, ':', '.'), 1) AS product, PARSENAME(REPLACE(eventtext, ':', '.'), 2) AS Adjustment, PARSENAME(REPLACE(eventtext, ':', '.'), 3) AS Swapped etc. |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-07-21 : 11:26:47
|
good call! |
|
|
ScottPletcher
Aged Yak Warrior
550 Posts |
Posted - 2014-07-21 : 13:14:13
|
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. |
|
|
|
|
|
|
|