Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 基于SSRS中其他数据集的值填充颜色_Sql Server_Reporting Services_Expression_Ssrs 2014_Ssrs 2017 - Fatal编程技术网

Sql server 基于SSRS中其他数据集的值填充颜色

Sql server 基于SSRS中其他数据集的值填充颜色,sql-server,reporting-services,expression,ssrs-2014,ssrs-2017,Sql Server,Reporting Services,Expression,Ssrs 2014,Ssrs 2017,我正在尝试根据表格记录填充颜色 从SQL Server AdventureWorks2017数据库: select * from [HumanResources].[Department] 我有两个数据集: 1st : select * from [HumanResources].[Department] DepartmentID Name

我正在尝试根据表格记录填充颜色

从SQL Server AdventureWorks2017数据库:

          select * from [HumanResources].[Department]
我有两个数据集:

           1st : select * from [HumanResources].[Department]

            DepartmentID                         Name                            GroupName                                          Status
            ----------------------------------------------------------------------------------------------------------------------------------------
            1                                Engineering                    Research and Development                       Cancelled
            2                                Tool Design                    Research and Development                       Blacklist
            3                                Sales                          Sales and Marketing                            Approved
            4                                Marketing                      Sales and Marketing                            All good
            5                                Purchasing                     Inventory Management                           xxx
            6                                Research and Development       Research and Development                       yyy
            7                                Production                     Manufacturing                                  zzz
            8                                Production                     Control Manufacturing                          xxx
            9                                Human Resources                Executive General and Administration           zzz
            10                               Finance                        Executive General and Administration           aaa
            11                               Information Services           Executive General and Administration           xxx
            12                               Document Control               Quality Assurance                              yyy
            13                               Quality Assurance              Quality Assurance                              zzz
            14                               Facilities and Maintenance     Executive General and Administration           aaa
            15                               Shipping and Receiving         Inventory Management                           bbb
            16                               Executive                      Executive General and Administration           aaa
第二次,我需要获得如下数据并显示在SSRS报告中:

                Name0                                Name1                                      Name2                           Name3                                      Name4
            -----------------------------------------------------------------------------------------------------------------------------------------------------------------
            Document Control           Facilities and Maintenance                Information Services           Production Control                  Research and Development
             Engineering                Finance                                     Marketing                      Purchasing                       Sales
             Executive                 Human Resources                             Production                   Quality Assurance                   Shipping and Receiving
              NULL                     NULL                                         NULL                         NULL                               Tool Design
我使用以下查询获取的上述数据:

            WITH Table1 AS
            (
                SELECT  [Name]
                FROM    [HumanResources].[Department]
            ), CTE AS
            (
                SELECT  [Name], COL, ROW_NUMBER() OVER(PARTITION BY Col ORDER BY [Name]) AS Row
                FROM    (   SELECT [Name],
                                    5 - NTILE(5) OVER(ORDER BY [Name] DESC) AS Col
                            FROM Table1  
                        ) c
            )
            SELECT [0], [1], [2], [3], [4]
            FROM CTE 
            PIVOT (MAX([Name]) FOR Col IN ([0], [1], [2], [3], [4])) AS Pvt
            ORDER BY Row;
此外,除上述要求外,另一项要求是根据“组名”和“状态”(即“另一个数据集”值)填充第二个结果集中的颜色; 我使用的是:

       select * from [HumanResources].[Department]
我正在尝试以下表达式,以填充第二个数据集的颜色:

      =IIF(LOOKUP((Fields!ID0.Value or Fields!ID1.Value or Fields!ID2.Value or Fields!ID3.Value or Fields!ID4.Value),Fields!Name.Value,Fields!GroupName.Value="Research and Development","DsetAll"),"GREEN","WHITE") 

      =IIF(LOOKUP((Fields!ID0.Value or Fields!ID1.Value or Fields!ID2.Value or Fields!ID3.Value or Fields!ID4.Value),Fields!Name.Value,Fields!GroupName.Value,"DsetAll")="Research and Development","GREEN","WHITE")
问题不在于上述表达式中的任何一个工作正常

编辑: 下面的表达式看起来工作正常:

 =IIF(LOOKUP(Fields!ID0.Value ,Fields!Name.Value,Fields!GroupName.Value,"DsetAll")="Research and Development","BLUE","RED")
看起来“查找”中的“或”不起作用。我怎样才能做到这一点?还有别的办法吗

在第二个结果集中,想法是:

        if groupname "Research and Development" and status is "Cancelled" then "Green"
       if groupname "Research and Development" and status is "Blacklist" then "Green"
       if groupname "Sales and Marketing" and status is "Approved" then "Green"
                if status is "All good" then Gray
                if groupname "Manufacturing" then Blue
                if groupname "Control   Manufacturing" then red
                if groupname "Executive General and Administration" then pink
                if groupname "Quality Assurance" then Violet
                Else its should be white
第一个表达式未显示任何填充颜色。 此外,空/空白不应具有任何颜色

第二个表达式有错误:

            The Error occurred during local report processing.
            The definition of the report '/ColorTest' is invalid.
            The BackgroundColor expression for the text box 'ID0' contains an error: [BC30201] Expression expected.

我怎样才能做到这一点?或者,请让我知道是否有其他方法可以实现同样的目标?谢谢,这样表达式应该可以工作,但我建议使用另一种方法(可能使用计算字段将特定信息存储在一个字段中,而不是五个单独的ID字段中):


看到Name0到Name4都是静态列。。您可以简单地将每个列连接回资源表,以获取状态并基于结果。。返回颜色,然后将该颜色用于报表中的单元格

我将首先用cte包装您的枢轴,并获得整洁的输出

差不多

    , my_pivot_result as (

     SELECT [0], [1], [2], [3], [4]
                FROM CTE 
                PIVOT (MAX([Name]) FOR Col IN ([0], [1], [2], [3], [4])) AS Pvt

    )
,my_status as (

select my_pivot_result .* 
, isnull(col1_name.status,'') as col1_status
, isnull(col1_name.groupname,'') as col1_groupname
, isnull(col2_name.status,'') as col2_status
, isnull(col2_name.groupname,'') as col2_groupname
, isnull(col3_name.status,'') as col3_status
, isnull(col3_name.groupname,'') as col3_groupname
, isnull(col4_name.status,'') as col_status
, isnull(col4_name.groupname,'') as col4_groupname

from my_pivot_result 

left join [HumanResources].[Department] col1_name
 on col1_name.name = my_pivot_result.name0

left join [HumanResources].[Department] col2_name
 on col2_name.name = my_pivot_result.name1

left join [HumanResources].[Department] col3_name
 on col3_name.name = my_pivot_result.name2

left join [HumanResources].[Department] col4_name
 on col4_name.name = my_pivot_result.name3
)

Select * from my_status
现在,对于每一行,您都应该有一个状态和组名。。现在使用case语句为color构建另一列

类似于

    case when  col1_groupname = 'Research and Development'
       and col1_status in('Blacklist', 'Cancelled') then 'Green'

 else 'white' end as col1_color

    .
    .
    .
继续构建案例陈述,直到您拥有所有的组合


现在在前端,使用每个单元格的表达式来显示颜色并使用颜色字段值

有什么原因不能使用组名作为颜色加入数据集,然后使用组名而不是lookuper?如果颜色是静态的。。为什么不在数据集查询中使用case语句对其进行硬编码?我总是把查找作为最后的手段。。如果且仅当我无法加入到我需要的数据中,对不起,我没有清楚地了解它。你能提供一些细节吗?组名,我不想在报告中显示。此组名称用于设置背景单元格颜色。此外,颜色是静态的,但记录数是动态的。谢谢。您能否显示数据透视查询的结果,以便我们查看结果与[HumanResources].[Department]中的select*之间的可能关系?数据透视查询的结果在问题中。透视查询上方的表(Name0、Name1…Name4列)
    case when  col1_groupname = 'Research and Development'
       and col1_status in('Blacklist', 'Cancelled') then 'Green'

 else 'white' end as col1_color

    .
    .
    .