Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How to extract the first word of a string in SQL?

0
Posted

How to extract the first word of a string in SQL?

0

Try this,

select substr (full_name, 1, instr (full_name || ‘  ‘, ‘ ‘, 1, 2) – 1)
from   dual;

0

We can use a UDF for that which takes the text and delimiter as input parameters and returns the first word.

 

CREATE FUNCTION GetFirstWord
(
    @text varchar(2000),@delimiter char(1)
)
RETURNS varchar(2000)
AS
BEGIN  

    Declare @firstWord varchar(200) 
    set @firstWord= SUBSTRING(@text,1,(charindex(@delimiter,@text+@delimiter)-1))
    return @firstword

END
GO

 

 

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123