Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to extract the word in a string.

Author  Topic 

ryoka12
Starting Member

9 Posts

Posted - 2015-01-19 : 04:15:37
Hi,

How can i extract string but ignore the last word.
Example.

declare x varchar(max)='the quick brown fox jump over the lazy dog.'

i just want to ignore the word 'dog.'

Thanks and help much appreciated.

nagino
Yak Posting Veteran

75 Posts

Posted - 2015-01-19 : 04:49:47
declare @x varchar(max)='the quick brown fox jump over the lazy dog.'
select left(@x, len(@x) - charindex(' ', reverse(@x)) + 1)


-------------------------------------
From Japan
Sorry, my English ability is limited.
Go to Top of Page

ryoka12
Starting Member

9 Posts

Posted - 2015-01-19 : 06:30:26
@nagino It works perfectly.
Thanks.. ^_^
Go to Top of Page
   

- Advertisement -