简体   繁体   English

列名 > “ ”?

[英]Column_name > “ ”?

I came across a query today where inside an IIF statement there was a comparison where column > " " .我今天遇到了一个查询,其中在IIF语句中有一个比较 where column > " " I have never seen this before and I am not even sure what it is doing.我以前从未见过这个,我什至不确定它在做什么。 I am familiar with comparing strings with < and >.我熟悉将字符串与 < 和 > 进行比较。 IE "B" < "W" returns True. IE "B" < "W" 返回 True。

However what exactly does comparing a column to a string of spaces do?然而,将一列与一串空格进行比较究竟是做什么的呢?

The line in the select statement: select 语句中的行:

,IIf([CD] > "     " AND [DT]=#12/31/9999#,[MT],[O]) AS [Final]

Can someone explain exactly what this comparison is doing and why would you want this?有人可以准确解释这个比较在做什么,你为什么想要这个?

Your logic is checking that CD is larger than a field whose name consists only of spaces.您的逻辑是检查CD是否大于名称仅包含空格的字段。 That seems highly unlikely.这似乎极不可能。

My guess is that you are either using MS Access because the date constant is not compatible with SQL Server.我的猜测是您要么使用 MS Access,因为日期常量与 SQL 服务器不兼容。 In SQL Server this would be:在 SQL 服务器中,这将是:

IIf([CD] > '     ' AND [DT] = #12/31/9999#, [MT], [O]) AS [Final]

This is validating that the string does not start with a bunch of spaces.这是验证字符串不是以一堆空格开头的。 It is actually a rather pathetic way of doing this;这实际上是一种相当可悲的方式。 more typically LTRIM() would be involved.更典型地会涉及LTRIM()

I might further speculate that CD is exactly five characters long.我可能会进一步推测CD正好是五个字符长。 In this case, the logic is checking that it is not all spaces.在这种情况下,逻辑是检查它不是所有的空格。 This would be particularly applicable if the type were CHAR(5) NOT NULL .如果类型是CHAR(5) NOT NULL ,这将特别适用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM