Case,是Null和参数

时间:2014-06-05 21:32:07

标签: sql sql-server

我有一个查询,我想要显示" 0"如果"提示"是" NULL"否则只显示提示。这是我的问题:

SELECT t1.sName         ,
       t1.sLocationDesc ,
       t1.sOtherNumber  ,
       t1.RegHours      ,
       t1.OTHours       ,
       CASE
         WHEN t2.EmployeeHours / t3.DepartmentHrs * @Tip IS NULL THEN 0
         ELSE t2.EmployeeHours / t3.DepartmentHrs * @Tip
       END AS Tip

我收到错误:

  

传入表格数据流(TDS)远程过程调用(RPC)   protocal流不正确。参数3(" @ Tip")用户定义的类型   指定了无效的用户类型..

这里有任何帮助吗?

2 个答案:

答案 0 :(得分:1)

为什么要使用案例

试试这个

SELECT t1.sName, 
       t1.sLocationDesc, 
       t1.sOtherNumber, 
       t1.RegHours, 
       t1.OTHours, 
       ISNULL(t2.EmployeeHours / t3.DepartmentHrs * @Tip,0) AS 'Tip'

BTW我觉得错误不是由于您的案例陈述

答案 1 :(得分:0)

试试这个:

SELECT t1.sName, t1.sLocationDesc, t1.sOtherNumber, t1.RegHours, t1.OTHours,
       CASE WHEN (@Tip IS NULL OR @Tip=0) THEN 0 ELSE 
       t2.EmployeeHours/t3.DepartmentHrs * @Tip END AS Tip