select a1, a2, a3, a4, value, case when a1 is not null and a2 is not null and a3 is not null and a3 is not null then value+1 else value end as NewValue from 表名
这样就好create table #t1(a1 varchar(10),a2 varchar(10),a3 varchar(10),a4 varchar(10),D int)insert #t1 select null,'a','b','c',1select a1,a2,a3,a4,case when (a1+a2+a3+a4) is not null then D+1 else D end from #t1
如果a1-a4中有一个为null,那么他们+在一起也会为空
drop table #t1 create table #t1(a1 varchar(10),a2 varchar(10),a3 varchar(10),a4 varchar(10),D int)insert #t1 select null,'a','b','c',1 union all select 'aa','a','b','c',1 select a1,a2,a3,a4,case when (a1+a2+a3+a4) is not null then D+1 else D end value from #t1
如: declare @a datetime,@b datetime,@c int,@d varchar(100) set @a=getdate() set @B=getdate() set @c=1 set @d='a' select @a+@b+@c+@d这样会出错。
--无论四个字段是什么数据类型,这样都可以:select a1, a2, a3, a4, value, case when a1 is not null and a2 is not null and a3 is not null and a3 is not null then value+1 else value end as NewValue from 表名
create proc dbo.Proc_update as begin set nocount on update table set value=value+1 where a1 is not null and a2 is not null and a3 is not null and a4 is not null end
select
a1,
a2,
a3,
a4,
value,
case
when a1 is not null and a2 is not null and a3 is not null and a3 is not null then value+1
else value
end as NewValue
from 表名
select null,'a','b','c',1select a1,a2,a3,a4,case when (a1+a2+a3+a4) is not null then D+1 else D end
from #t1
create table #t1(a1 varchar(10),a2 varchar(10),a3 varchar(10),a4 varchar(10),D int)insert #t1
select null,'a','b','c',1 union all
select 'aa','a','b','c',1 select a1,a2,a3,a4,case when (a1+a2+a3+a4) is not null then D+1 else D end value
from #t1
declare @a datetime,@b datetime,@c int,@d varchar(100)
set @a=getdate()
set @B=getdate()
set @c=1
set @d='a'
select @a+@b+@c+@d这样会出错。
a1,
a2,
a3,
a4,
value,
case
when a1 is not null and a2 is not null and a3 is not null and a3 is not null then value+1
else value
end as NewValue
from 表名
as
begin
set nocount on
update table set value=value+1 where a1 is not null and a2 is not null and a3 is not null and a4 is not null
end