我有这个在 Oracle 中工作的查询,但我想将它转换为使用 Coalesce,因为我在使用 Visual Studio 时遇到了一些问题。
SELECT *
FROM a Left Join b on b.institution_code=a.institution_code
WHERE
(upper(a.Login_Name)=UPPER('%' || :Login_Name || '%') OR :Login_Name IS NULL)
AND (upper(a.Display_Name) Like UPPER('%' || :Display_Name || '%') OR :Display_Name IS NULL)
AND (upper(a.Email_Address)=UPPER(:Email_Address) OR :Email_Address IS NULL)
AND ((a.institution_code=:institution_code) OR :institution_code IS NULL)
AND (upper(b.institution_desc) Like UPPER('%' || :institution_desc || '%') OR :institution_desc IS NULL)
这有效
WHERE
Upper(a.Display_Name) LIKE Upper('%' || COALESCE(:Display_Name,a.Display_Name) || '%')
AND upper(a.Login_Name)=Upper(COALESCE(:Login_Name,a.Login_Name))
AND upper(a.Email_Address)=Upper(COALESCE(:Email_Address,a.Email_Address))
但是当我尝试将机构代码和机构描述字段转换为使用合并时,我没有从查询中得到任何结果。
当我添加这些行时没有结果
AND a.institution_code=COALESCE(:institution_code,a.institution_code)
AND (Upper(b.institution_desc) LIKE Upper('%' || COALESCE(:institution_desc,b.institution_desc) || '%'))