How can I slice a string that is separated by /
?
Example:
id | column1 |
---|---|
01 | x/pp/llllll |
02 | lll/k/uu/llll/nbbbb |
03 | zzzzzz/wwww/s/aa |
What I want is to return the first input up to the comma:
id | column1 |
---|---|
1 | x |
2 | lll |
3 | zzzzzz |
How can I slice a string that is separated by /
?
Example:
id | column1 |
---|---|
01 | x/pp/llllll |
02 | lll/k/uu/llll/nbbbb |
03 | zzzzzz/wwww/s/aa |
What I want is to return the first input up to the comma:
id | column1 |
---|---|
1 | x |
2 | lll |
3 | zzzzzz |
The below statement should do the trick!
SELECT id, SUBSTRING_INDEX(column1, '/', 1) AS column1
FROM [TableName];
Welcome! As B001ᛦ said, it might not be a good idea depending on your data.
To manipulate strings, look at the String functions.
SELECT SUBSTRING_INDEX(column1, '/', 1) FROM foo;
SQL Fiddle : http://sqlfiddle.com/#!9/2ff4f7