我有一个选择语句
select
name
,age
from table_employees
where id=@impId;
我想检查年龄是否为空而不是返回零。我尝试了以下但它不起作用
select
name
,age isnull(age,0.00)
from table_employees
where id=@impId;
请让我知道如何解决这个问题。谢谢
我有一个选择语句
select
name
,age
from table_employees
where id=@impId;
我想检查年龄是否为空而不是返回零。我尝试了以下但它不起作用
select
name
,age isnull(age,0.00)
from table_employees
where id=@impId;
请让我知道如何解决这个问题。谢谢
在 SQL Server 2005 或更高版本中,您可以使用该COALESCE
函数:
SELECT
name
, COALESCE(age, 0) as age
FROM table_employees
WHERE id=@impId
该函数一个一个地计算它的参数,并返回第一个非NULL
值。
试试这个方法
select
name,age=isnull(age,0.00)
from table_employees
where id=@impId;
或者
select
name,
isnull(age,0.00) as age
from table_employees
where id=@impId;
你可以试试这个: -
select
name
, COALESCE(age,0) as age
from table_employees
where id=@impId;
建议经常被忽视的 COALESCE:
select
name,
coalesce(age, 0.00) as age_not_null
from table_employees
where id = @impId;
请尝试以下操作:
select
name
,isnull(age,0.00)
from table_employees
where id=@impId;
尝试:
SELECT name,isnull(age,0)
FROM table_employees
WHERE id=@impId;
ISNULL
是 SQL Server 的语句。您不能将列名放在它前面。
所以,试试这个:
SELECT name, ISNULL(age,0.00) AS age
FROM table_employees
WHERE id=@impId;