Split MySQL String to two fieldsWhat is the difference between String and string in C#?How do I iterate over the words of a string?How do I read / convert an InputStream into a String in Java?Case insensitive 'Contains(string)'How do I split a string on a delimiter in Bash?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?Does Python have a string 'contains' substring method?How to split a string in JavaWhy is char[] preferred over String for passwords?
Can Legal Documents Be Siged In Non-Standard Pen Colors?
Where did Edmond Malone place the Tempest in the chronology of Shakespeare's plays?
Are the IPv6 address space and IPv4 address space completely disjoint?
Are paving bricks differently sized for sand bedding vs mortar bedding?
Loading commands from file
What percentage of fillings performed today are done with mercury amalgam?
The IT department bottlenecks progress. How should I handle this?
New brakes for 90s road bike
How can I block email signup overlays or javascript popups in Safari?
When were female captains banned from Starfleet?
Rising and falling intonation
Why should universal income be universal?
Symbol used to indicate indivisibility
Did arcade monitors have same pixel aspect ratio as TV sets?
Why did the EU agree to delay the Brexit deadline?
How to explain what's wrong with this application of the chain rule?
Does the Location of Line-Dash-Wedge Notations Matter?
Lowest total scrabble score
A social experiment. What is the worst that can happen?
Creepy dinosaur pc game identification
What is Cash Advance APR?
What does routing an IP address mean?
Count the occurrence of each unique word in the file
How should I respond when I lied about my education and the company finds out through background check?
Split MySQL String to two fields
What is the difference between String and string in C#?How do I iterate over the words of a string?How do I read / convert an InputStream into a String in Java?Case insensitive 'Contains(string)'How do I split a string on a delimiter in Bash?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?Does Python have a string 'contains' substring method?How to split a string in JavaWhy is char[] preferred over String for passwords?
In short, I have a PHP form that asks for employee id, email and password to add the user to the DB which works fine.
The table in the DB also has Firstname and Lastname fields.
Because the powers that be feel asking for fname and lname in the form is a step too far, I wanted to split the employee id so that it populated at least the fname. Last name we're not overly bothered about as it isn't unique anyway.
In short, each employee id is made up of the same format, ie, first name followed by a number (ie John12345, Mark67890 (5 digits per employee id after the firstname)). I would like to insert into the DB the employee id, and whilst it's doing that, Split out at the first number (or last letter) and populate the firstname (the rest of the string split can be purged as long as the full employee id is inserted into the employee_id).
I've read that a split function is not available in MySQL so I'm trying to figure out the best way to achieve this.
mysql string split
add a comment |
In short, I have a PHP form that asks for employee id, email and password to add the user to the DB which works fine.
The table in the DB also has Firstname and Lastname fields.
Because the powers that be feel asking for fname and lname in the form is a step too far, I wanted to split the employee id so that it populated at least the fname. Last name we're not overly bothered about as it isn't unique anyway.
In short, each employee id is made up of the same format, ie, first name followed by a number (ie John12345, Mark67890 (5 digits per employee id after the firstname)). I would like to insert into the DB the employee id, and whilst it's doing that, Split out at the first number (or last letter) and populate the firstname (the rest of the string split can be purged as long as the full employee id is inserted into the employee_id).
I've read that a split function is not available in MySQL so I'm trying to figure out the best way to achieve this.
mysql string split
add a comment |
In short, I have a PHP form that asks for employee id, email and password to add the user to the DB which works fine.
The table in the DB also has Firstname and Lastname fields.
Because the powers that be feel asking for fname and lname in the form is a step too far, I wanted to split the employee id so that it populated at least the fname. Last name we're not overly bothered about as it isn't unique anyway.
In short, each employee id is made up of the same format, ie, first name followed by a number (ie John12345, Mark67890 (5 digits per employee id after the firstname)). I would like to insert into the DB the employee id, and whilst it's doing that, Split out at the first number (or last letter) and populate the firstname (the rest of the string split can be purged as long as the full employee id is inserted into the employee_id).
I've read that a split function is not available in MySQL so I'm trying to figure out the best way to achieve this.
mysql string split
In short, I have a PHP form that asks for employee id, email and password to add the user to the DB which works fine.
The table in the DB also has Firstname and Lastname fields.
Because the powers that be feel asking for fname and lname in the form is a step too far, I wanted to split the employee id so that it populated at least the fname. Last name we're not overly bothered about as it isn't unique anyway.
In short, each employee id is made up of the same format, ie, first name followed by a number (ie John12345, Mark67890 (5 digits per employee id after the firstname)). I would like to insert into the DB the employee id, and whilst it's doing that, Split out at the first number (or last letter) and populate the firstname (the rest of the string split can be purged as long as the full employee id is inserted into the employee_id).
I've read that a split function is not available in MySQL so I'm trying to figure out the best way to achieve this.
mysql string split
mysql string split
asked 2 days ago
Lucero79Lucero79
1225
1225
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You must use Left and Right functions as follow:
SET @employee = 'Employee12345';
SELECT RIGHT(@employee ,5), LEFT(@employee, LENGTH(@employee)-5);
Because employee number code is a 5 digit number, then you could use this code.
If you wanna insert into another table, you must use INSERT INTO SELECT Statement as Follow:
Insert into _newtable Select RIGHT(_employee ,5), LEFT(_employee, LENGTH(_employee)-5) FROM _oldtable;
Where _employee is your oldtable field.
ah ok, I see. The users are already in a table, so all I really want to do is run the query to split what is there into another column, rather than a new table, and the perfect world would be the submit from the PHP form would do the magic.
– Lucero79
2 days ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281205%2fsplit-mysql-string-to-two-fields%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You must use Left and Right functions as follow:
SET @employee = 'Employee12345';
SELECT RIGHT(@employee ,5), LEFT(@employee, LENGTH(@employee)-5);
Because employee number code is a 5 digit number, then you could use this code.
If you wanna insert into another table, you must use INSERT INTO SELECT Statement as Follow:
Insert into _newtable Select RIGHT(_employee ,5), LEFT(_employee, LENGTH(_employee)-5) FROM _oldtable;
Where _employee is your oldtable field.
ah ok, I see. The users are already in a table, so all I really want to do is run the query to split what is there into another column, rather than a new table, and the perfect world would be the submit from the PHP form would do the magic.
– Lucero79
2 days ago
add a comment |
You must use Left and Right functions as follow:
SET @employee = 'Employee12345';
SELECT RIGHT(@employee ,5), LEFT(@employee, LENGTH(@employee)-5);
Because employee number code is a 5 digit number, then you could use this code.
If you wanna insert into another table, you must use INSERT INTO SELECT Statement as Follow:
Insert into _newtable Select RIGHT(_employee ,5), LEFT(_employee, LENGTH(_employee)-5) FROM _oldtable;
Where _employee is your oldtable field.
ah ok, I see. The users are already in a table, so all I really want to do is run the query to split what is there into another column, rather than a new table, and the perfect world would be the submit from the PHP form would do the magic.
– Lucero79
2 days ago
add a comment |
You must use Left and Right functions as follow:
SET @employee = 'Employee12345';
SELECT RIGHT(@employee ,5), LEFT(@employee, LENGTH(@employee)-5);
Because employee number code is a 5 digit number, then you could use this code.
If you wanna insert into another table, you must use INSERT INTO SELECT Statement as Follow:
Insert into _newtable Select RIGHT(_employee ,5), LEFT(_employee, LENGTH(_employee)-5) FROM _oldtable;
Where _employee is your oldtable field.
You must use Left and Right functions as follow:
SET @employee = 'Employee12345';
SELECT RIGHT(@employee ,5), LEFT(@employee, LENGTH(@employee)-5);
Because employee number code is a 5 digit number, then you could use this code.
If you wanna insert into another table, you must use INSERT INTO SELECT Statement as Follow:
Insert into _newtable Select RIGHT(_employee ,5), LEFT(_employee, LENGTH(_employee)-5) FROM _oldtable;
Where _employee is your oldtable field.
answered 2 days ago
Nerio EspinaNerio Espina
111
111
ah ok, I see. The users are already in a table, so all I really want to do is run the query to split what is there into another column, rather than a new table, and the perfect world would be the submit from the PHP form would do the magic.
– Lucero79
2 days ago
add a comment |
ah ok, I see. The users are already in a table, so all I really want to do is run the query to split what is there into another column, rather than a new table, and the perfect world would be the submit from the PHP form would do the magic.
– Lucero79
2 days ago
ah ok, I see. The users are already in a table, so all I really want to do is run the query to split what is there into another column, rather than a new table, and the perfect world would be the submit from the PHP form would do the magic.
– Lucero79
2 days ago
ah ok, I see. The users are already in a table, so all I really want to do is run the query to split what is there into another column, rather than a new table, and the perfect world would be the submit from the PHP form would do the magic.
– Lucero79
2 days ago
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281205%2fsplit-mysql-string-to-two-fields%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown