gpt4 book ai didi

SQL REPLACE 未按预期工作

转载 作者:行者123 更新时间:2023-12-02 17:18:55 26 4
gpt4 key购买 nike

我有一个临时表,我试图从特定列中消除所有空白。但是我的替换根本不起作用。这是我的代码

IF OBJECT_ID('tempdb..#attempt1temptable') IS NOT NULL 
BEGIN
DROP TABLE #attempt1temptable
END
GO

CREATE TABLE #attempt1temptable
(
temp_description varchar(MAX),
temp_definition varchar(MAX)
)

INSERT INTO #attempt1temptable
SELECT graphic_description, graphic_definition
FROM graphic

UPDATE #attempt1temptable SET temp_description=REPLACE(temp_description, ' ', '')
UPDATE #attempt1temptable SET temp_description=REPLACE(temp_description, char(160), '')

--I have no idea why it won't update correctly here

select temp_description, LEN(temp_description) from #attempt1temptable

Insert 和 select 按预期工作,但它不会将 temp_description 更新为没有空格。查询的结果给了我 temp_description 没有任何改变。我在这里做错了什么?

最佳答案

尝试替换一些其他空白字符:

select replace(replace(replace(replace(
description
,char(9)/*tab*/,'')
,char(10)/*newline*/,'')
,char(13)/*carriage return*/,'')
,char(32)/*space*/,'')
from #attemp1temptable

关于SQL REPLACE 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44595845/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com