Last post Mar 17, 2017 02:16 PM by limno
Mar 17, 2017 01:22 PM|georgenaffah|LINK
I have a column in my sql server table that contains text , lets say a row has the following text :
"this is a test that was made the year 2012 cause in the year 2013 we was down"
what i need is to check if the year occurs more than once if yes , the text should be updated to be : "this is a test that was made the year 2012 cause in the "
so I need to keep everything before the second occurrence and delete everything from last occurrence till the end any help please ?
Mar 17, 2017 02:16 PM|limno|LINK
CREATE TABLE test (id int,
Insert Into test Values(1,'this is a test that was made the year 2012 cause in the year 2013 we was down' )
;with mycte as (
Select id, col, Replace(col, 'year','') col2 from test)
select col , Reverse(Stuff(reverse(col),1,charindex(Reverse('year'),reverse(col))+4,'')) colNew from mycte
drop table test