How to extract the first word of a string in SQL?
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