2017-03-17 42 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搜索列的名稱即時無效的列名稱。 。 。也許你錯過了一個需要插入的地方。 –

相關問題