使用此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
您是否必須擁有'UNION ALL'或者您的SP是否有多個個人查詢? – 2013-03-18 19:33:33
我編輯了這個問題。你是這個意思嗎? – Jess 2013-03-18 19:47:05