table:
  a1,a2,a3,a4,value功能:
  如果a1,a2,a3,a4每一项的值不为空,value+1

解决方案 »

  1.   


    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 表名
      

  2.   

    这样就好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
      

  3.   

    如果a1-a4中有一个为null,那么他们+在一起也会为空
      

  4.   

    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
      

  5.   

    如:
    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这样会出错。
      

  6.   

    --无论四个字段是什么数据类型,这样都可以: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 表名
      

  7.   

    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
      

  8.   

    好象是我没说明白了。对不住大家了。那这样假设:username;a1不为空,value+1;a2不为空,value+2;a3不为空,value+3;a4不为空,value+10,此时又该如何呢?假设还有另一个表tagle2:logindate(datetime),username(与上表关联)。如果三个月内每登录一次,value+1;这个表又如何处理呢?我只会用前台的代码来写,但这样太慢了,存储过程却不会,麻烦大家给写一个。如果分数不够没关系,可以再加。我分很多的。
      

  9.   

    全部转化为varchar去处理,然后相加,如果为null,那么就加一。