在 JOIN 条件下使用 RTRIM
我想将包含产品的两个表按其描述放在一起
表 1: [..fields..] [DESCRIPTION1] [..fields..]
表 2: [.. fields..] [DESCRIPTION2] [..fields..]
SELECT [..fields..] FROM TABLE1,TABLE2
INNER JOIN TABLE1
ON TABLE1.DESCRIPTION1 = TABLE2.DESCRIPTION2
但在很多情况下,两个表中都有以空格结尾的描述,我也想得到它们,这就是为什么我这样尝试:
SELECT [..fields..] FROM TABLE1,TABLE2
INNER JOIN TABLE1
ON TABLE1.DESCRIPTION1 = TABLE2.DESCRIPTION2
OR RTRIM(TABLE1.DESCRIPTION1) = RTRIM(TABLE2.DESCRIPTION2)
这不会产生错误,但不会带来更多数据。
有人能帮助我吗?
感谢您的每一次帮助:)
提前致谢,哈利
I want to put two tables which are containing Products together by their DESCRIPTIONs
TABLE 1: [..fields..] [DESCRIPTION1] [..fields..]
TABLE 2: [..fields..] [DESCRIPTION2] [..fields..]
SELECT [..fields..] FROM TABLE1,TABLE2
INNER JOIN TABLE1
ON TABLE1.DESCRIPTION1 = TABLE2.DESCRIPTION2
But in lots of cases, there are descriptions in both tables ending with an space, i also want to get them, thatswhy i tried it that way:
SELECT [..fields..] FROM TABLE1,TABLE2
INNER JOIN TABLE1
ON TABLE1.DESCRIPTION1 = TABLE2.DESCRIPTION2
OR RTRIM(TABLE1.DESCRIPTION1) = RTRIM(TABLE2.DESCRIPTION2)
Which produces no error, but does not bring more data.
Is anybody able to help me?
Every help is appreciated :)
Thanks in Advance, Harry
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题可能是描述末尾的 CRLF 字符,这些字符在 SSMS 中看起来像空格,并且不会被
RTRIM()
删除。要进行检查,请查看选择
where Description like '%' + char(13) + char(10)
是否返回任何内容。如果描述末尾似乎只有 1 个空格,请单独尝试char(13)
或char(10)
。最后,制表符 (char(9)
) 也看起来像一个空格,因此您也可以尝试这样做。如果它确实是这些字符中的任何一个,您可以使用
REPLACE
来删除它们:我发现了此处。
The problem might be CRLF characters at the end of the Description, which will look like spaces in SSMS and won't be removed by
RTRIM()
.To check, see if selecting
where Description like '%' + char(13) + char(10)
returns anything. If it looks like there is only 1 space at the end of the Description, try eitherchar(13)
orchar(10)
alone. Finally, a Tab (char(9)
) would also look like a space, so you could try that as well.If it does turn out to be any of these characters, you could use
REPLACE
to get rid of them:which I found here.
根据数据类型,您根本不需要 RTRIM()。我还想知道旧式和现代连接语法的混合是否会让您绊倒(尽管这应该会产生更多行,而不是更少)。这会产生什么结果?
Depending on the data type, you shouldn't need RTRIM() at all. I also wonder if your mix of old-style and modern join syntax is tripping you up (though that should yield more rows, not less). What does this yield?
您不需要 OR
You do not need the OR