-1

我有这个查询字符串

  select a.name, a.address
  from table_main a
  where a.id=3345

对于此查询,我尝试添加 a.amount 如果它为 null 如果不返回某个值则返回零

 select a.name, a.addres, isnull(a.amount, 0) else 333
 from table_main a
 where a.id=3345

任何想法如何解决这个问题,如果 a.amount 为空,如果不是返回值,则返回零,即 333 谢谢

4

5 回答 5

1

你可以使用一个case语句

select a.name, 
       a.addres,
       case when a.amount is null 
            then 0 
            else 333
       end as amount_check
from table_main a
wher a.id = 3345
于 2013-10-25T05:40:37.263 回答
1
select a.name, a.addres,
      case when a.amount is null then 0 else 333 end amount 
 from table_main a
 wher a.id=3345
于 2013-10-25T05:40:45.620 回答
1

试试这个(Use Case-When 语句)

select a.name, a.addres, case when a.amount is NULL then 0 else 333 end as Amount
from table_main a
wher a.id=3345
于 2013-10-25T05:41:17.783 回答
0

您需要将它包含在 CASE 语句中

SELECT a.NAME,
   a.addres,
   CASE 
      WHEN a.amount IS NULL
         THEN 0
      ELSE 333
   END
FROM table_main a where a.id = 3345
于 2013-10-25T05:40:17.340 回答
0

尝试这个:

select a.name, a.addres,
case when a.amount is null then 0 else 333 end
from table_main a where a.id=3345
于 2013-10-25T05:42:15.773 回答