问题描述
我希望这对 SQL 专家来说是一个有趣的谜题.
I hope this is an interesting puzzle for an SQL expert out there.
当我运行以下查询时,我希望它不会返回任何结果.
When I run the following query, I would expect it to return no results.
结果返回单行:
问题是人们正在从电子邮件等中复制和粘贴值,并且他们以某种方式进入表格.我正在将此作为一个单独的问题进行研究,因为我将 LTRIM(RTRIM(Foo)) 作为 INSERT 和 UPDATE 触发器,但有些正在以某种方式通过网络.
The issue is that people are copying and pasting values from emails etc. and they're getting into the table somehow. I am looking into this as a separate issue as I am LTRIM(RTRIM(Foo)) as an INSERT and UPDATE trigger, but some are getting through the net somehow.
我需要更多地了解这种行为以及我应该如何解决它.
I need to know more about this behaviour and how I should work around it.
还值得注意的是 LEN(Foo) 也是奇数,如下:
It is also worth noting that LEN(Foo) is odd too, as follows:
给出以下结果:
没有任何横向思考,我需要将 WHERE 子句更改为什么才能按预期返回 0 结果?
Without any lateral thinking, what do I need to change my WHERE clause to in order to return 0 results as expected?
推荐答案
答案是添加以下子句:
运行以下查询...
...产生以下结果...
...produces the following results...
DATALENGTH 可用于测试两个 VARCHAR 的相等性,因此可以按如下方式更正原始查询:
DATALENGTH can be used to test the equality of two VARCHAR, therefore the original query can be corrected as follows:
我也做了一个函数来代替=
I also made a function to be used instead of =
..这是对用作尾随字符的所有 256 个字符的测试,以证明它有效..
..Here is a test for all 256 characters used as trailing characters to prove that it works..
这篇关于在 VARCHAR 中使用尾随空格 SQL Server SELECT 时的未记录功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!