Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

Get the First and Last Word from a String or Sentence

DECLARE @Sentence    VARCHAR(MAX) = 'The quick brown fox jumps over the lazy dog'

SELECT SUBSTRING(@Sentence, 1, CHARINDEX(' ', @Sentence) - 1) AS [First Word],
       REVERSE(SUBSTRING(REVERSE(@Sentence), 1,                CHARINDEX(' ', REVERSE(@Sentence)) - 1)) AS [Last Word]
Source by www.sql-server-helper.com #
 
PREVIOUS NEXT
Tagged: #Get #First #Last #Word #String #Sentence
ADD COMMENT
Topic
Name
7+4 =