Jump to content

[SOLVED] Field Split on Database Level


wsantos

Recommended Posts

We are trying to do a match up of database from one server to another. However the thing is we want to split a certain columns into three columns since it contains three data in that single field. Can this be done on the database level?

Link to comment
Share on other sites

Nope XXXXXX is a variable length string. Field 2 and 3 is fixed length so I can split it. Another issue is I can do this on a script but we are wondering if we can split it on database level. If so, how. Or perhaps a link to a resource. Thanks

Link to comment
Share on other sites

This works, there might be a better way of doing it, you just need to change data to the field name

 

SELECT SUBSTRING_INDEX(data,' ',1) AS col1,

LEFT(SUBSTRING_INDEX(data, ' ', -1),5) AS col2,

SUBSTRING_INDEX(data, '-', -1) AS col3

FROM table_name

 

let me know how you get on

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.