我想在我的SSRS报告中显示以下案例类型,即使它们具有空值。
Project Finance
,Whole of Market
,CustomBuild
SELECT Count(ct.CaseTypeDesc)AS Done, ct.CaseTypeDesc,ap.StatusDesc As [Mortgage Status],SUM(pm.ProcFeeExp + pm.ArrangementFee) As Total ,u.Fullname as Advisor
FROM dbo.tbl_Profile AS p
INNER JOIN dbo.tbl_Profile_Mortgage AS pm
ON p.ID = pm.FK_ProfileID
INNER JOIN dbo.tbl_AppStatus AS ap
ON pm.MortgageStatus = ap.StatusID
INNER JOIN dbo.tbl_CaseTypes AS ct
ON p.CasetypeID = ct.CaseTypeID
LEFT JOIN dbo.tbl_User AS u
ON p.Advisor = u.UserID
WHERE pm.MortgageStatus = 7
AND ct.CaseTypeDesc IN ('Project Finance','Whole of Market','CustomBuild')
AND p.Advisor IN (266,104,172,145,177,253,286,261,289,138)
AND (
pm.DatePassed BETWEEN @Start AND @End
OR pm.DateCompleted BETWEEN @Start AND @End
OR pm.DateOffered BETWEEN @Start AND @End
)
GRoup By u.Fullname,ct.CaseTypeDesc,ap.StatusDesc
当我运行此报告时,可能无法计算Whole of Market
不过,我仍希望我的报告按Whole of Market
分组并显示0
。
非常感谢任何帮助。
答案 0 :(得分:0)
如果您使用GROUP BY
子句,则不会区分NULL
值。我认为一个简单的解决方案是使用UNION ALL
运算符来为不同的CaseTypeDesc
添加行。
这样的事情:
select count(CaseTypeDesc) ...
from ...
where CaseTypeDesc = 'Project Finance'
UNION ALL
select count(CaseTypeDesc)...
from ...
where CaseTypeDesc = 'Whole of Market'
UNION ALL
select count(CaseTypeDesc)...
from ...
where CaseTypeDesc = 'CustomBuild'
即使它没有显示在您的查询中,它也会将整个市场计数归零。
这应该是您的查询。
SELECT Count(ct.CaseTypeDesc)AS Done, 'Project Finance' CaseTypeDesc,ap.StatusDesc As [Mortgage Status],
SUM(pm.ProcFeeExp + pm.ArrangementFee) As Total ,u.Fullname as Advisor
FROM dbo.tbl_Profile AS p
INNER JOIN dbo.tbl_Profile_Mortgage AS pm
ON p.ID = pm.FK_ProfileID
INNER JOIN dbo.tbl_AppStatus AS ap
ON pm.MortgageStatus = ap.StatusID
INNER JOIN dbo.tbl_CaseTypes AS ct
ON p.CasetypeID = ct.CaseTypeID
LEFT JOIN dbo.tbl_User AS u
ON p.Advisor = u.UserID
WHERE pm.MortgageStatus = 7
AND ct.CaseTypeDesc = 'Project Finance'
AND p.Advisor IN (266,104,172,145,177,253,286,261,289,138)
AND (
pm.DatePassed BETWEEN @Start AND @End
OR pm.DateCompleted BETWEEN @Start AND @End
OR pm.DateOffered BETWEEN @Start AND @End
)
UNION ALL
SELECT Count(ct.CaseTypeDesc)AS Done, 'Whole of Market' as CaseTypeDesc,ap.StatusDesc As [Mortgage Status],
SUM(pm.ProcFeeExp + pm.ArrangementFee) As Total ,u.Fullname as Advisor
FROM dbo.tbl_Profile AS p
INNER JOIN dbo.tbl_Profile_Mortgage AS pm
ON p.ID = pm.FK_ProfileID
INNER JOIN dbo.tbl_AppStatus AS ap
ON pm.MortgageStatus = ap.StatusID
INNER JOIN dbo.tbl_CaseTypes AS ct
ON p.CasetypeID = ct.CaseTypeID
LEFT JOIN dbo.tbl_User AS u
ON p.Advisor = u.UserID
WHERE pm.MortgageStatus = 7
AND ct.CaseTypeDesc = 'Whole of Market'
AND p.Advisor IN (266,104,172,145,177,253,286,261,289,138)
AND (
pm.DatePassed BETWEEN @Start AND @End
OR pm.DateCompleted BETWEEN @Start AND @End
OR pm.DateOffered BETWEEN @Start AND @End
)
UNION ALL
SELECT Count(ct.CaseTypeDesc)AS Done, 'CustomBuild' as CaseTypeDesc,ap.StatusDesc As [Mortgage Status],
SUM(pm.ProcFeeExp + pm.ArrangementFee) As Total ,u.Fullname as Advisor
FROM dbo.tbl_Profile AS p
INNER JOIN dbo.tbl_Profile_Mortgage AS pm
ON p.ID = pm.FK_ProfileID
INNER JOIN dbo.tbl_AppStatus AS ap
ON pm.MortgageStatus = ap.StatusID
INNER JOIN dbo.tbl_CaseTypes AS ct
ON p.CasetypeID = ct.CaseTypeID
LEFT JOIN dbo.tbl_User AS u
ON p.Advisor = u.UserID
WHERE pm.MortgageStatus = 7
AND ct.CaseTypeDesc = 'CustomBuild'
AND p.Advisor IN (266,104,172,145,177,253,286,261,289,138)
AND (
pm.DatePassed BETWEEN @Start AND @End
OR pm.DateCompleted BETWEEN @Start AND @End
OR pm.DateOffered BETWEEN @Start AND @End
)
如果这有助于您,请告诉我。