gpt4 book ai didi

sql - 在sql server表中搜索ASCII值

转载 作者:行者123 更新时间:2023-12-03 03:24:19 24 4
gpt4 key购买 nike

我有一个表,其中一个字段需要清理。基本表结构如下:

create table testComments(id int, comments text)

在注释列中,某些行有许多“回车符”(char(13)) 和“换行符”(char(10))。如果每行有多个分组,我需要能够修改它。到目前为止,我的基本选择语句如下:

  select count(id)
from testComments
where comments like('%' + char(13) + char(10) + char(13) + char(10) + '%')

此查询将找到结果

"This is a entry in the testComments crlf
crlf
In the comments field that works"

虽然查询不会找到结果,但如果评论列出如下:

"This is an entry in the testComments crlf
crlf
crlf
That will not work"

查询只会返回上述数据的 1 条记录。知道如何更改查询以返回 2 的计数吗?

最佳答案

使用您提供给我们的代码,您的查询应该可以正常工作。所以细节似乎有所不同,我怀疑 GolezTrol 的评论是正确的——一些 CRLF 对实际上只是单独的 CR 或 LF 字符。

试试这个:

select count(id)
from #testComments
where comments like('%' + char(13) + char(10) + char(13) + char(10) + '%')
or comments like('%' + char(10) + char(10) + '%')
or comments like('%' + char(13) + char(13) + '%')

关于sql - 在sql server表中搜索ASCII值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17430497/

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