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 2012 Forums
 Transact-SQL (2012)
 remove last letter in the word of a sentence

Author  Topic 

misterraj
Yak Posting Veteran

94 Posts

Posted - 2014-12-23 : 07:36:15
I have a sentence/word and for each word in the sentence if a word finishes with 's' i want to remove the letter 's'.
Note if and only 's' letter is the last letter in a word.


thanks
venkat.

sz1
Aged Yak Warrior

555 Posts

Posted - 2014-12-23 : 08:43:00
The kind of thing:

declare @String varchar(max)
set @String = 'tests and more tests'

IF (RIGHT(@String, 1) = 's')
set @String = LEFT(@String, LEN(@String) - 1)
Select @string

We are the creators of our own reality!
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2014-12-23 : 08:45:22
SELECT REPLACE(sentence,'s ', ' ') FROM myTable

For S followed by punctuation:

SELECT REPLACE(REPLACE(REPLACE(sentence,'s.','.'),'s,',','),'s!','!') FROM myTable

For sentence ending in S:

SELECT CASE WHEN sentence LIKE '%s' THEN STUFF(sentence,LEN(sentence)-1,1,'') ELSE sentence END FROM myTable
Go to Top of Page

misterraj
Yak Posting Veteran

94 Posts

Posted - 2014-12-23 : 09:31:18
thanks. great!!!
Go to Top of Page
   

- Advertisement -