0

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.

iminiki
  • 2,549
  • 12
  • 35
  • 45
John_Doe
  • 59
  • 7

4 Answers4

0

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

Tim
  • 551
  • 3
  • 23
0
SELECT CONCAT(SUBSTRING(SUBSTRING_INDEX(first,' ',1),1,3),SUBSTRING(SUBSTRING_INDEX(first,' ',-1),1,3) )FROM Test;

Try this...

Sujith Kumar
  • 28
  • 1
  • 7
0

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
nbk
  • 45,398
  • 8
  • 30
  • 47
0

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)
Divyesh patel
  • 967
  • 1
  • 6
  • 21