Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL Server从第二次出现到结束删除所有内容_Sql_Sql Server_Match - Fatal编程技术网

SQL Server从第二次出现到结束删除所有内容

SQL Server从第二次出现到结束删除所有内容,sql,sql-server,match,Sql,Sql Server,Match,我的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 " 所以我需要在第二次出现之前保留所有内容,并删除从上次出现到结束的所有内容 有什么帮助吗?

我的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 "
所以我需要在第二次出现之前保留所有内容,并删除从上次出现到结束的所有内容


有什么帮助吗?

这很痛苦,但你可以做到:

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

有效年限是多少年。1973年有效吗?2199有效吗?当我插入要搜索的列名时,我得到的列名无效in@GeorgeNaffah . . . 也许你错过了一个需要插入的地方。