1

使用此 SP 构建报告。如果报表没有要显示的数据,我们应该只显示 tbl_CompanyProfile,但报表显示来自第二个选择的所有空字段。我关心的是:如何从第二个选择中隐藏空值并仅显示 tbl_CompanyProfile 字段?

SELECT Company_Name, Company_Address, Company_ContactNo, Company_Email, 
Company_Website, 'NULL' AS NAME, 'NULL' AS DATE, 0 AS AMOUNT, 
'NULL' AS DEPARTMENT, 0 AS Age, @from AS StartDate, @to AS EndDate
FROM     tbl_CompanyProfile

UNION ALL

SELECT '--' , '--' , '--' , '--' , '--' , tbl_IPD.ipd_pfname + ' ' + tbl_IPD.ipd_plname AS NAME,
CONVERT(VARCHAR, tbl_IPD.ipd_doa, 103) AS DATE, 
ISNULL(SUM(tbl_fee.fee_amount), 0) AS AMOUNT, tblDepartment.DeptName AS DEPARTMENT,
tbl_IPD.ipd_age AS Age, @from AS StartDate, @to AS EndDate
FROM     tbl_fee LEFT OUTER JOIN
tbl_IPD ON tbl_fee.ipd_id = tbl_IPD.ipd_id LEFT OUTER JOIN
tblDepartment ON tbl_IPD.ipd_dpt = tblDepartment.DeptId
WHERE  (tbl_IPD.ipd_doa BETWEEN @from AND @to)
GROUP BY tbl_IPD.ipd_pfname, tbl_IPD.ipd_plname, tbl_IPD.ipd_doa, 
tblDepartment.DeptName, tbl_IPD.ipd_age         
4

2 回答 2

1

您将 'NULL' 设置为字符串值。这不是 NULL 值。如果通过删除单引号将“NULL”更改为 NULL,则报告应将值显示为空白。

于 2013-03-18T19:41:03.903 回答
0

添加:

having SUM(tbl_fee.fee_amount) > 0

到您的工会中的第二个选择。

这将使第二个选择不返回行。

于 2013-03-18T23:42:11.240 回答