我正在尝试执行以下声明:
update dbo.CaseTable
set Quick=REPLACE(Quick,
"Case files have been archived. To have file access restored, please enter a helpdesk ticket with the full case name. Case files have been archived. To have file access restored, please enter a helpdesk ticket with the full case name.",
"Case files have been archived. To have file access restored, please enter a helpdesk ticket with the full case name.")
我收到以下错误:
Msg 103,Level 15,State 4,Line 2 以' Case文件开头的标识符已存档。要恢复文件访问权限,请输入包含完整案例名称的帮助台票证。案例档案'太长。最大长度为128。
如果这个字符串太长,怎么能替换它?
答案 0 :(得分:1)
您已使用双引号作为替换字符串,请使用单引号。下面的查询应该工作正常。基本上,双引号内提供的文本被视为列名。
set Quick=REPLACE(Quick, 'Case files have been archived. To have file access restored, please enter a helpdesk ticket with the full case name. Case files have been archived. To have file access restored, please enter a helpdesk ticket with the full case name.', 'Case files have been archived. To have file access restored, please enter a helpdesk ticket with the full case name.')
由于sql不允许替换ntext类型,请使用以下查询。
Quick = CAST(REPLACE(CAST(Quick as NVarchar(MAX)), 'Case files have been archived. To have file access restored, please enter a helpdesk ticket with the full case name. Case files have been archived. To have file access restored, please enter a helpdesk ticket with the full case name.', 'Case files have been archived. To have file access restored, please enter a helpdesk ticket with the full case name.') AS NText)