代码之家  ›  专栏  ›  技术社区  ›  Gary Thomann

ssrs order by case isnull-查询工作,ssrs错误

  •  0
  • Gary Thomann  · 技术社区  · 6 年前

    查询可以正常工作并按应该的方式排序。但是当SSRS数据集的一部分出现查询错误。 错误按大小写表达式的顺序缩小,如图所示。语法被接受。 运行期间的第一条错误消息:“报告处理期间发生错误。(rsprocessingaborted)“ 错误弹出窗口的详细信息按钮显示下面的Try n错误。

    select  <columns>
    from    <view>
    where   <criteria>
    order by 
    
    > error condition - try 1
            -- errors "The isnull function requires 2 argument(s)."
            case when isnull(<parm>, '') <> '' 
                 then <column to be sorted>
            end, 
    
    > error condition - try 2
            -- errors "An expression of non-boolean type specified in a context where a condition is expected, near ..."
            case when (<parm> is not null  or 
                       <parm> <> '')
                 then <column to be sorted>
            end, 
    
    > error condition - try 3
            -- errors "An expression of non-boolean type specified in a context where a condition is expected, near ..."
            case when <parm> is not null 
                 then <column to be sorted>
                 when <parm> <> ''
                 then <column to be sorted>
            end, 
    
            <more columns to sort>
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   junketsu    6 年前

    选项1:按原样运行整个查询,并将数据插入临时表。然后,您可以根据所需的ORDER BY列执行基于if-else的执行;首先在if语句中检查特定列的空值,然后使用所需的ORDER BY运行select。选项2:以强制方式处理这些空值,即在使用isNull约束插入临时表之前检查它们。 e.g. Col_1 = isnull(Col_1,'N/A') 。这样,您就有了一个确定的方法来按“不适用”筛选数据。然后,如果是基于其他的检查,则按顺序执行。选项2易于质量保证I.M.O.