使用此 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