1. <i id='yfuvH'><tr id='yfuvH'><dt id='yfuvH'><q id='yfuvH'><span id='yfuvH'><b id='yfuvH'><form id='yfuvH'><ins id='yfuvH'></ins><ul id='yfuvH'></ul><sub id='yfuvH'></sub></form><legend id='yfuvH'></legend><bdo id='yfuvH'><pre id='yfuvH'><center id='yfuvH'></center></pre></bdo></b><th id='yfuvH'></th></span></q></dt></tr></i><div id='yfuvH'><tfoot id='yfuvH'></tfoot><dl id='yfuvH'><fieldset id='yfuvH'></fieldset></dl></div>

    <legend id='yfuvH'><style id='yfuvH'><dir id='yfuvH'><q id='yfuvH'></q></dir></style></legend>
    1. <small id='yfuvH'></small><noframes id='yfuvH'>

        <bdo id='yfuvH'></bdo><ul id='yfuvH'></ul>
      <tfoot id='yfuvH'></tfoot>

    2. 在 text 或 ntext 数据类型上替换 REPLACE

      时间:2023-10-10

        <bdo id='laE5Z'></bdo><ul id='laE5Z'></ul>

      • <small id='laE5Z'></small><noframes id='laE5Z'>

              <legend id='laE5Z'><style id='laE5Z'><dir id='laE5Z'><q id='laE5Z'></q></dir></style></legend>
                <i id='laE5Z'><tr id='laE5Z'><dt id='laE5Z'><q id='laE5Z'><span id='laE5Z'><b id='laE5Z'><form id='laE5Z'><ins id='laE5Z'></ins><ul id='laE5Z'></ul><sub id='laE5Z'></sub></form><legend id='laE5Z'></legend><bdo id='laE5Z'><pre id='laE5Z'><center id='laE5Z'></center></pre></bdo></b><th id='laE5Z'></th></span></q></dt></tr></i><div id='laE5Z'><tfoot id='laE5Z'></tfoot><dl id='laE5Z'><fieldset id='laE5Z'></fieldset></dl></div>
              • <tfoot id='laE5Z'></tfoot>
                  <tbody id='laE5Z'></tbody>

                本文介绍了在 text 或 ntext 数据类型上替换 REPLACE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我需要更新/替换 datatable.column 中的数据.该表有一个名为 Content 的字段.我正在使用 REPLACE 函数.由于列数据类型是 NTEXT,SQL Server 不允许我使用 REPLACE 函数.

                I need to update/replace the data in datatable.column. The table has a field named Content. I'm using the REPLACE function. Since the column datatype is NTEXT, SQL Server doesn't allow me to use the REPLACE function.

                我无法更改数据类型,因为此数据库是 3rd 方软件表.更改数据类型将导致应用程序失败.

                I can't change the datatype because this database is 3rd party software table. Changing the datatype will cause the application to fail.

                UPDATE [CMS_DB_test].[dbo].[cms_HtmlText] 
                SET Content = REPLACE(Content,'ABC','DEF') 
                WHERE Content LIKE '%ABC%' 
                

                我收到此错误:

                消息 8116,级别 16,状态 1,第 1 行参数数据类型 ntext 对于替换函数的参数 1 无效.

                Msg 8116, Level 16, State 1, Line 1 Argument data type ntext is invalid for argument 1 of replace function.

                • 我可以用 T-SQL 解决这个问题吗?有人有如何阅读和循环的示例吗?
                • 由于这是一次性转换,也许我可以更改为另一种类型,但我担心我会弄乱数据.
                • 有一个主键字段:name: ID - integer - 它是一个身份....所以我也需要考虑这个.也许将 Identity 设置为 N 临时.

                  There is a primary key field: name: ID - integer - it's an identity.... So I need to think about this too. Maybe set the Identity to N temporary.

                  请教如何实现REPLACE功能?

                  Please advise on how to achieve the REPLACE function?

                  大约3000 条语句需要使用新解决方案进行更新.

                  Approx. 3000 statements need to be updated with a new solution.

                  推荐答案

                  IF您的数据不会溢出 4000 个字符并且您使用的是 SQL Server 2000 或兼容性8 级或 SQL Server 2000:

                  IF your data won't overflow 4000 characters AND you're on SQL Server 2000 or compatibility level of 8 or SQL Server 2000:

                  UPDATE [CMS_DB_test].[dbo].[cms_HtmlText] 
                  SET Content = CAST(REPLACE(CAST(Content as NVarchar(4000)),'ABC','DEF') AS NText)
                  WHERE Content LIKE '%ABC%' 
                  

                  对于 SQL Server 2005+:

                  For SQL Server 2005+:

                  UPDATE [CMS_DB_test].[dbo].[cms_HtmlText] 
                  SET Content = CAST(REPLACE(CAST(Content as NVarchar(MAX)),'ABC','DEF') AS NText)
                  WHERE Content LIKE '%ABC%' 
                  

                  这篇关于在 text 或 ntext 数据类型上替换 REPLACE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:SQL Server中如何确定不能转换为(decimal,float,int)的字段值 下一篇:计数表中值的连续出现次数

                相关文章

                <i id='lMF8U'><tr id='lMF8U'><dt id='lMF8U'><q id='lMF8U'><span id='lMF8U'><b id='lMF8U'><form id='lMF8U'><ins id='lMF8U'></ins><ul id='lMF8U'></ul><sub id='lMF8U'></sub></form><legend id='lMF8U'></legend><bdo id='lMF8U'><pre id='lMF8U'><center id='lMF8U'></center></pre></bdo></b><th id='lMF8U'></th></span></q></dt></tr></i><div id='lMF8U'><tfoot id='lMF8U'></tfoot><dl id='lMF8U'><fieldset id='lMF8U'></fieldset></dl></div>

              • <tfoot id='lMF8U'></tfoot>
                    <bdo id='lMF8U'></bdo><ul id='lMF8U'></ul>

                  1. <small id='lMF8U'></small><noframes id='lMF8U'>

                    <legend id='lMF8U'><style id='lMF8U'><dir id='lMF8U'><q id='lMF8U'></q></dir></style></legend>