t-sql替换双引号

发布于 2024-07-30 10:00:11 字数 345 浏览 1 评论 0原文

我有一个像 Replace(field,'\''','\"') 这样的 t-sql 语句,因为我有两个不同的结果 ''field1'' 和“field2”,但是如果我认为这两个不同的结果相同并想要将它们分组怎么办? 我选择通过用第二种样式替换第一个双引号来对这两个引号进行分组,但尽管替换了它们,但它们并不被解释为相同类型的引号。

我在这里缺少什么?

编辑:我正在尝试对文本相同但引号不同的数据进行分组,用户输入两个单引号“hello”和一个双引号“hello”,如果我有这两行,我试图将它们显示为一行作为“你好”,所以通过执行上面的语句我认为我应该能够做到这一点,但即使没有斜杠它也无法正常工作。

I have a t-sql statement like Replace(field,'\''','\"') because i have two different results
''field1'' and "field2" but what if i consider those two different results the same and want to group them. I choose to group those two by replacing the first double quotes with the second style but although replaced they are not interpreted as the same type of quote.

What I am missing here??

Edited: I am trying to group data where text is the same but quotes differ, user is entering two single quotes ''hello'' and one double quote "hello", if I have this two rows I am trying to display them as one as "hello", so by executing the above statement I think I should be able to do this, but it isn't working properly even without slashes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

方觉久 2024-08-06 10:00:11

看一下这段代码:

DECLARE @X  varchar(20)
SET @X='''''Hello"'

PRINT @X
PRINT REPLACE(@X,'''''','"')
PRINT REPLACE(REPLACE(@X,'''''',''''),'"','''')

这是输出:

''Hello"
"Hello"
'Hello'

SQL Server does not escapequotes with斜杠,单引号是用另一个单引号转义的。 这将打印一个单引号:

print ''''

这将打印两个单引号:

print ''''''

look at this code:

DECLARE @X  varchar(20)
SET @X='''''Hello"'

PRINT @X
PRINT REPLACE(@X,'''''','"')
PRINT REPLACE(REPLACE(@X,'''''',''''),'"','''')

here is the output:

''Hello"
"Hello"
'Hello'

SQL Server does not escape quotes with slashes, a single quote is escaped with another single quote. This will print one single qoute:

print ''''

this will print two single quotes:

print ''''''
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文