在我的存储过程中,我从三个表中获取数据,但出现此错误:
将数据类型 varchar 转换为数值时出错。
我认为问题出在:-
'NULL' AS DATE (in 1st query of this SP)------(1)
CONVERT(VARCHAR, tbl_IPD.ipd_doa, 103) AS DATE (in 2nd query of this SP)-----(2)
我的问题是:如何将 (1) 行转换为 varchar
SELECT
tbl_CompanyProfile.Company_Name, tbl_CompanyProfile.Company_Address,
tbl_CompanyProfile.Company_ContactNo, tbl_CompanyProfile.Company_Email,
tbl_CompanyProfile.Company_Website,
'NULL' AS NAME, 'NULL' AS DATE,
'NULL' 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