基于条件

时间:2015-06-15 13:45:33

标签: reporting-services ssrs-2008 ssrs-2008-r2 ssrs-2012

我想将报告格式化为:

enter image description here

我已经复制了这样的数据:

 IF EXISTS (SELECT * FROM sys .objects
WHERE object_id = OBJECT_ID(N'dbo.CompareVal' )
AND type in (N'U'))
    DROP TABLE dbo.CompareVal;
CREATE TABLE dbo.CompareVal
(CompareValID  INT          Not Null 
, ValName      NVARCHAR(75) Null
, Vehicle      INT          Null
, Driver       INT          Null
);
GO

INSERT INTO CompareVal(CompareValID, ValName, Vehicle, Driver)
VALUES(1,'ABC Company Value',10, 15)

--SELECT * FROM #CompareVal

 IF EXISTS (SELECT * FROM sys .objects
WHERE object_id = OBJECT_ID(N'dbo.GroupStatistic' )
AND type in (N'U'))
    DROP TABLE dbo.GroupStatistic;
CREATE TABLE GroupStatistic
(StatisticID      INT          IDENTITY(1,1)
, CompanyName     NVARCHAR(75) Null
, [Description]   NVARCHAR(75) Null
, VehicleAvalible INT          Null
, DriverAvailable INT          Null
);

INSERT INTO GroupStatistic(CompanyName, [Description], VehicleAvalible, DriverAvailable)
VALUES ('APC and Sons', 'Something..', 5, 7)
     , ('ABC Camp limited', 'We deliver..', 15, 15)
	 , ('Silas and Sons', 'Anything goes.', 10, 7)
	 , ('Richard and Co', 'Helping you all the way.', Null, Null)
	 , ('Kayla and Jane', '', 0, 3)
	 , ('James and Jane', '', 1, 0)

--SELECT * FROM #GroupStatistic

SELECT CompanyName
     , [Description]
	 , ISNULL(CAST(VehicleAvalible AS NVARCHAR(30)),'N/A') AS VehicleAvalible
	 , ISNULL(CAST(DriverAvailable AS NVARCHAR(30)),'No Driver available') AS DriverAvailable
	 , 0 AS TotalVehicles 
	 , 0 AS TotalDrivers
FROM GroupStatistic

  UNION 

SELECT '' AS CompanyName
     , 'Group Value Standard' AS [Description]
	 , CAST(Vehicle AS NVARCHAR(30)) AS VehicleAvalible
	 , CAST(Driver AS NVARCHAR(30)) AS DriverAvailable
	 , Vehicle
	 , Driver
FROM CompareVal

我对“VehicleAvailable”栏的表达是:

=Switch(Fields!Description.Value = "Group Value Standard" AND Fields!VehicleAvalible.Value = Fields!TotalVehicles.Value, "Black"
   , Fields!Description.Value = "Group Value Standard" AND Fields!VehicleAvalible.Value < Fields!TotalVehicles.Value, "Black"
   , Fields!Description.Value = "Group Value Standard" AND Fields!VehicleAvalible.Value > Fields!TotalVehicles.Value, "Black"
   , Fields!Description.Value <> "Group Value Standard" AND Fields!VehicleAvalible.Value < Fields!TotalVehicles.Value, "Gold"
   , Fields!Description.Value <> "Group Value Standard" AND Fields!VehicleAvalible.Value > Fields!TotalVehicles.Value, "Red"
   , Fields!Description.Value = "Group Value Standard" AND Fields!VehicleAvalible.Value = Fields!TotalVehicles.Value, "Blue"
   )

这不起作用,因为我将整数与文本值进行比较。如何格式化以获得如上图所示的结果?

1 个答案:

答案 0 :(得分:0)

我会在SELECT中添加一列,例如VehicleAvailableInt将返回一个整数值 - 然后在Expression中使用它。

你也可以合理化你的Switch代码 - 在我看来,前3个案例可以被替换为:

Fields!Description.Value = "Group Value Standard" , "Black"

也可能永远不会到达你的最后一个Switch案例?