wsantos Posted August 20, 2007 Share Posted August 20, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/65826-solved-field-split-on-database-level/ Share on other sites More sharing options...
kirk112 Posted August 20, 2007 Share Posted August 20, 2007 is all the data in the columns you want to split the same lenght? Quote Link to comment https://forums.phpfreaks.com/topic/65826-solved-field-split-on-database-level/#findComment-328907 Share on other sites More sharing options...
wsantos Posted August 20, 2007 Author Share Posted August 20, 2007 nope...data is "XXXXXXXXXXXXX G9999-99999" we want to split it into 1: XXXXXXXXXXXXX 2: G9999 3: 99999 Quote Link to comment https://forums.phpfreaks.com/topic/65826-solved-field-split-on-database-level/#findComment-328910 Share on other sites More sharing options...
kirk112 Posted August 20, 2007 Share Posted August 20, 2007 is XXXXXXXXXXXXX always 13 chars long and is field 2 and 3 always split by a - Quote Link to comment https://forums.phpfreaks.com/topic/65826-solved-field-split-on-database-level/#findComment-328915 Share on other sites More sharing options...
wsantos Posted August 20, 2007 Author Share Posted August 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/65826-solved-field-split-on-database-level/#findComment-328916 Share on other sites More sharing options...
kirk112 Posted August 20, 2007 Share Posted August 20, 2007 This will give you col1 and col3, I will have a look at getting col2 to work later tonight SELECT SUBSTRING_INDEX(data,' ',1) AS col1, SUBSTRING_INDEX(data, '-', -1) AS col3 FROM table_name Quote Link to comment https://forums.phpfreaks.com/topic/65826-solved-field-split-on-database-level/#findComment-328921 Share on other sites More sharing options...
kirk112 Posted August 20, 2007 Share Posted August 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/65826-solved-field-split-on-database-level/#findComment-328924 Share on other sites More sharing options...
wsantos Posted August 20, 2007 Author Share Posted August 20, 2007 didn't work since the first column can have multiple whitespaces too.thanks Quote Link to comment https://forums.phpfreaks.com/topic/65826-solved-field-split-on-database-level/#findComment-328930 Share on other sites More sharing options...
wsantos Posted August 20, 2007 Author Share Posted August 20, 2007 thanks we can take it from here. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/65826-solved-field-split-on-database-level/#findComment-328935 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.