2017-03-17 43 views
0

我有我的SQL Server表包含文本列,比方说,一个列有如下文字:SQL Server中删除一切从第二次出现到结束

"this is a test that was made the year 2012 cause in the year 2013 we was down" 

我需要的是检查是否一年以上发生;如果是,该文本应更新为:

"this is a test that was made the year 2012 cause in the " 

所以我需要把一切都在第二occurence之前删除一切从最后一次出现到结束

任何帮助吗?

+0

什么范围的几年将是有效的。 1973年有效吗? 2199是否有效? –

回答

1

这是痛苦的,但你可以做到这一点:

select (case when col like '%year%year%' 
      then left(col, 
         charindex('year', col, charindex('year', col) + 4) - 1 
        ) 
      else col 
     end) as first_year_only 
+0

即时通讯插入我想要在 –

+0

@GeorgeNaffah搜索列的名称即时无效的列名称。 。 。也许你错过了一个需要插入的地方。 –

相关问题