开发者

Ms access query for dont show blank filed

I have a query that has a couple of text fields where in the filter criteria I put <> "Power". When I put this criteria in, it also does not show me records where the field is blank. If I leave the criteria empty, it shows me all records including the records with the开发者_如何学Python blank fields.

How do I get the query to exclude the criteria Power but still show records where that field is blank?


Try adding an OR IS NULL:

<> "Power" OR IS NULL


SELECT *
  FROM YourTable
 WHERE 'T' = SWITCH(
                    your_col IS NULL,     'T', 
                    your_col = ' ',       'T', 
                    your_col <> 'Power',  'T'
                   );


Try using ANSI SQL function COALESCE like this

SELECT *
FROM MyTable
WHERE COALESCE(MyColumn, '') <> 'Power'


A blank field could mean the field is Null or it contains a zero length string (""). You can test for either of those conditions by concatenating the field with another zero length string. If the string length of that combination is zero, you know the field must be either Null or zero length string.

SELECT *
FROM YourTable
WHERE
       Your_column <> 'Power'
    OR Len(Your_column & '') = 0;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜