[英]Returning value from select statement
我有這個查詢字符串
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為null,則返回零(如果不等於返回值,即333)
您可以使用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
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
試試這個(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
您需要將其包含在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
嘗試這個:
select a.name, a.addres,
case when a.amount is null then 0 else 333 end
from table_main a where a.id=3345
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.