日期:2014-05-17  浏览次数:20397 次

请教一个SQL算法
我有N(N>2)个参数,现在要对这些参数进行加(+)或者减(-)运算,如果所有参数都为NULL,则结果为NULL,其中只要有一个有值,其它为NULL的都为0参与运算,求指导怎么写。
declare @dt1 int ,@dt2 int,@dt3 int,@dt4 int
set @dt1=NULL;set @dt2=NULL;set @dt3=NULL;set @dt4=NULL

------解决方案--------------------
--看这样行吗
declare @dt1 int ,@dt2 int,@dt3 int,@dt4 int
set @dt1=NULL;set @dt2=NULL;set @dt3=NULL;set @dt4=NULL
select nullif(isnull(@dt1,0)+isnull(@dt2,0)+isnull(@dt3,0)+isnull(@dt4,0),0)