在SQL Server中替换NZ的任何函数? [英] Any functions to replace NZ in SQL Server?

查看:185
本文介绍了在SQL Server中替换NZ的任何函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Access前端移出一些查询,并在SQL Server 2005 express中创建了

的视图。在某些数字字段中,我经常使用nz

(即nz([MyField],0))如果字段为空则返回零。

在SQL Server中有什么相同的东西吗?现在我正在使用

CASE WHEN ......但是看起来像是一个非常多的脚本来写

用零替换null。


非常感谢任何帮助。


谢谢!

解决方案

使用coalesce或isnull


声明@v int

选择合并(@ v,0),isnull(@ v,0)

Denis SQL威胁
http://sqlservercode.blogspot.com/


2006年4月20日星期四20:25:47 GMT,Rico < r c o l l e s s @ h e m m n n

g w y y。 c。修改这部分内容>写道:

我正在从Access前端移出一些查询,并在SQL Server 2005 express中创建它们的视图。在某些数字字段中,我经常使用nz
(即nz([MyField],0))如果字段为空则返回零。
在SQL中是否有任何与此相同的内容服务器?现在我正在使用
CASE WHEN ...但是看起来像是一个非常多的脚本来写
用零替换null。

任何帮助都会非常感谢。

谢谢!




你好Rico,


使用COALESCE:


COALESCE(arg1,arg2,arg3,arg4,...)

返回所提供参数的第一个非NULL。你至少需要两个参数
,但你可以添加任意多个参数。


-

Hugo Kornelis, SQL Server MVP


谢谢你们,


在我有机会发回信息之前,我找到了ISNULL。 (为什么我

总是在我发布后立即找到解决方案)。


是否有关于在IsNull上使用Coalesce的论据?


谢谢!


" Hugo Kornelis" <胡** @ perFact.REMOVETHIS.info.INVALID>在消息中写道

news:j7 ******************************** @ 4ax.com ...

2006年4月20日星期四20:25:47 GMT,Rico < r c o l l e s s @ h e m m n n
g w y y。 c。修改这部分内容>写道:

我正在从Access前端移出一些查询,并在SQL Server 2005 express中创建它们的视图。在某些数字字段中,我经常使用nz
(即nz([MyField],0))如果字段为空,则返回零。
是否有任何等价物在SQL Server中这个?现在我正在使用
CASE WHEN ...但是看起来像是一个非常多的脚本来写
用零替换null。

任何帮助都会非常感谢。

谢谢!



你好Rico,

使用COALESCE:

COALESCE( arg1,arg2,arg3,arg4,...)

返回提供的参数的第一个非NULL。你至少需要两个参数,但你可以添加任意多个参数。

-
Hugo Kornelis,SQL Server MVP



I''m moving some queries out of an Access front end and creating views out of
them in SQL Server 2005 express. In some of the numeric fields, I use nz
quite often, ( i.e. nz([MyField],0)) to return a zero if the field is null.
Is there anything equivalent to this in SQL Server? Right now I''m using
CASE WHEN ... but it seems like an awful lot of script to write just to
replace null with a zero.

Any help would be greatly appreciated.

Thanks!

解决方案

use coalesce or isnull

declare @v int
select coalesce(@v,0),isnull(@v,0)
Denis the SQL Menace
http://sqlservercode.blogspot.com/


On Thu, 20 Apr 2006 20:25:47 GMT, "Rico" <r c o l l e n s @ h e m m i n
g w a y . c o mREMOVE THIS PART IN CAPS> wrote:

I''m moving some queries out of an Access front end and creating views out of
them in SQL Server 2005 express. In some of the numeric fields, I use nz
quite often, ( i.e. nz([MyField],0)) to return a zero if the field is null.
Is there anything equivalent to this in SQL Server? Right now I''m using
CASE WHEN ... but it seems like an awful lot of script to write just to
replace null with a zero.

Any help would be greatly appreciated.

Thanks!



Hi Rico,

Use COALESCE:

COALESCE (arg1, arg2, arg3, arg4, ...)

returns the first non-NULL of the supplied arguments. You need at least
two arguments, but you can add as many as you like.

--
Hugo Kornelis, SQL Server MVP


Thanks Guys,

I wound up finding ISNULL before I had a chance to post back. (why do I
always find the solution right after I post).

Is there an argument for using Coalesce over IsNull?

Thanks!

"Hugo Kornelis" <hu**@perFact.REMOVETHIS.info.INVALID> wrote in message
news:j7********************************@4ax.com...

On Thu, 20 Apr 2006 20:25:47 GMT, "Rico" <r c o l l e n s @ h e m m i n
g w a y . c o mREMOVE THIS PART IN CAPS> wrote:

I''m moving some queries out of an Access front end and creating views out
of
them in SQL Server 2005 express. In some of the numeric fields, I use nz
quite often, ( i.e. nz([MyField],0)) to return a zero if the field is
null.
Is there anything equivalent to this in SQL Server? Right now I''m using
CASE WHEN ... but it seems like an awful lot of script to write just to
replace null with a zero.

Any help would be greatly appreciated.

Thanks!



Hi Rico,

Use COALESCE:

COALESCE (arg1, arg2, arg3, arg4, ...)

returns the first non-NULL of the supplied arguments. You need at least
two arguments, but you can add as many as you like.

--
Hugo Kornelis, SQL Server MVP



这篇关于在SQL Server中替换NZ的任何函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆