SQL Server select-where 语句问题

发布于 2024-09-10 10:30:39 字数 417 浏览 0 评论 0原文

我在 Windows Server 2008 Enterprise 上使用 SQL Server 2008 Enterprise。我有一个关于 SQL Server 2008 中 tsql 的问题。对于 select-where 语句,有两种不同的形式,

(1) select where foo [some value] 和 [some other value] 之间,

(2) select where foo >= [某个值] 和 foo <= [某个其他值]?我不确定 Between-and 是否始终与使用 <= 和 >= 符号相同?

顺便说一句:它们是否始终相同 - 即使对于不同类型的数据(例如比较数值,比较字符串值),如果有人可以提供一些文档来证明它们是否始终相同,以便我可以从中了解更多信息。

提前致谢, 乔治

I am using SQL Server 2008 Enterprise on Windows Server 2008 Enterprise. I have a question about tsql in SQL Server 2008. For select-where statement, there are two differnet forms,

(1) select where foo between [some value] and [some other value],

(2) select where foo >= [some value] and foo <= [some other value]? I am not sure whether between-and is always the same as using <= and >= sign?

BTW: whether they are always the same - even for differnet types of data (e.g. compare numeric value, comparing string values), appreciate if anyone could provide some documents to prove whether they are always the same, so that I can learn more from it.

thanks in advance,
George

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

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

发布评论

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

评论(1

回忆凄美了谁 2024-09-17 10:30:39

是的,它们总是一样的。 联机丛书中的条目 BETWEEN

如果 BETWEEN 的值等于,则返回 TRUE
test_expression 大于或
等于 begin_expression 的值
并且小于或等于的值
结束表达式。

事实上,通过查看执行计划,您可以轻松地看到这一点。您会看到 Between 甚至没有出现在文本中。它已被替换为 >=<= ,两者之间没有区别。

SELECT * FROM master.dbo.spt_values 
WHERE number between 1 and 3 /*Numeric*/

SELECT * FROM master.dbo.spt_values 
WHERE name between 'a' and 'b' /*String*/

select * from sys.objects 
WHERE create_date between GETDATE() and GETDATE()+100 /*Date*/

输入图片此处描述

Yes they are always the same. The entry in Books Online for BETWEEN says

BETWEEN returns TRUE if the value of
test_expression is greater than or
equal to the value of begin_expression
and less than or equal to the value of
end_expression.

Indeed you can see this easily by looking at the execution plans. You will see that Between doesn't even appear in the text. It has been replaced with >= and <= there is no distinction made between the two.

SELECT * FROM master.dbo.spt_values 
WHERE number between 1 and 3 /*Numeric*/

SELECT * FROM master.dbo.spt_values 
WHERE name between 'a' and 'b' /*String*/

select * from sys.objects 
WHERE create_date between GETDATE() and GETDATE()+100 /*Date*/

enter image description here

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