I´m trying to get the first 3 letters from first word and 3 from next word. The names in database are different. If name is James Fiddler i want it to be JAMFID
Tried to use SUBSTRING_INDEX but i cant understand how.
Have you already tried the LEFT() function in combination with the LOCATE() function? https://www.w3resource.com/mysql/string-functions/mysql-left-function.php
In your case, I think it would be (haven't tested this)
SELECT LEFT(name, LOCATE(' ', name) - 1), LEFT(name, LOCATE(' ', name))
Maybe this article can help you: Get all characters before space in MySQL
SELECT CONCAT(SUBSTRING(SUBSTRING_INDEX(first,' ',1),1,3),SUBSTRING(SUBSTRING_INDEX(first,' ',-1),1,3) )FROM Test;
Try this...
You can try
SELECT UPPER(CONCAT(LEFT(SUBSTRING_INDEX(@name, ' ', 1),3)
,LEFT(SUBSTRING_INDEX(@name, ' ', -1),3)));
Which gives You
UPPER(CONCAT(LEFT(SUBSTRING_INDEX(@name, ' ', 1),3)
,LEFT(SUBSTRING_INDEX(@name, ' ', -1),3)))
JAMFID
May help full to you:
Declare @name varchar(100)='ABCDEFG PQRSTU'
SELECT Left(substring(@name, 1,charindex(' ',@name)),3)+LEFT(substring(@name, charindex(' ',@name)+1,len(@name)-charindex(' ',@name)+1),3)