简体   繁体   English

MS Access检查是否为空null

[英]MS Access check for for last none null

I have the following table - Item and Sizes are the field names: 我有下表-项目和大小是字段名称:

Item  Size1   Size2   Size3  Size4  Size5  Size6  Size7
ABY    S
XYZ    S       M       L      XL
FGH    8       10      12     14
QWE            4       5      6      7

But I need to arrive at the following: 但我需要得出以下几点:

Item     SizeRange
ABY        S
XYZ        S-XL
FGH        8-14
QWE        4-7

I can do this via a SWITCH function and checking where size <> '' however in reality the fields go up to size 15. Is there an easier, cleaner way to achieve this? 我可以通过SWITCH函数并检查大小<> ''来完成此操作,但是实际上字段的大小达到15。是否有更简单,更干净的方法来实现此目的? ie VBA? 即VBA?

Regards, 问候,

Michael 迈克尔

If you redesign your table to this format: 如果将表重新设计为以下格式:
在此处输入图片说明

Each size has a weight, or order value so you know which order they're used in. 每个尺寸都有权重或订单值,因此您知道它们的使用顺序。
This SQL, which may not be the best implementation (I'm a little rusty) will give the table shown in your example: 这个SQL可能不是最好的实现(我有些生疏),它将给出示例中的表:

SELECT    T1.Item
        , MinSize & IIF(Not MaxSize Is Null,' - ' & MaxSize,'') AS SizeRange
        , MaxSize
FROM    (
            SELECT TOP 1      Item
                            , Size AS MinSize
            FROM              tbl_ItemSizes
            GROUP BY          Item
                            , Size
                            , Weighting
            ORDER BY          Weighting
        ) T1 LEFT JOIN
        (
            SELECT TOP 1      Item
                            , Size AS MaxSize
            FROM              tbl_ItemSizes
            GROUP BY          Item
                            , Size
                            , Weighting
            ORDER BY          Weighting DESC
        ) T2 ON T1.Item = T2.Item  

(Someone feel free to rewrite the SQL). (有人可以随时重写SQL)。

在此处输入图片说明

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

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