表table中有a,b,c,d列a(char)
b(datetime)
c(datetime)触发器的条件是:
当更新table时,若b = ''  ,a显示为'无数据'
              若b <> '' 且b<c时,a显示为'finish',否则显示'unfinished'
         

解决方案 »

  1.   

    為''時=1900-01-01 00:00:00.000
    cast('' as datetime)
      

  2.   

    create trigger  trigger1 on TB 
    for  update
    as
    update inserted
    set a='无数据' 
    where b = ''  update inserted
    set a=示'unfinished' 
    where b <c and b<>'' update inserted
    set a='finish'
    where b <>''
    and b>=c  
      

  3.   


    汗。我的SQL2000显示的是<null>。刚学SQL,很多知识不清楚,正在看书中。这个问题现在急用,所以就来求高手解答了,救急。
      

  4.   

    沒有唯一列時:
    create table T_update on T
    instead of update
    as
    set nocount on ;
    delete t where checksum(*)in (select checksum(*) from deleted )insert T(a,b,c,d)
    select [a]=case when b is null then '无数据' when b<c then 'finish' else 'unfinished' end,b,c,d
    from inserted
      

  5.   

    明白了。谢谢。我用了if..else  和case when  都不行。
      

  6.   

    这个不用触发器比较好做
    写在存储过程里
    create procedure test
            @a char(100)
           @b datetime
           @c datetime
    as
    begin
           if @b = ''
           begin
              set @a = '无数据'
           end       if @b <> '' and @b < @c
           begin
              set @a = 'finish'
           end       if @b <> '' and @b >= @c
           begin
              set @a = 'unfinished'
           end       update [Table]
            set a = @a,
                b = @b,
                c = @c
           where
                   ..............end
      

  7.   

    create trigger T_update on T--打錯trigger
    instead of update
    as
    set nocount on ;
    delete t where checksum(*)in (select checksum(*) from deleted )
    insert T(a,b,c,d)
    select [a]=case when b is null then '无数据' when b<c then 'finish' else 'unfinished' end,b,c,d
    from inserted
      

  8.   

    create procedure test
            @a char(100)
           @b datetime
           @c datetime
    as
    begin
           if @b = '' or @b is null   --<Null>
           begin
              set @a = '无数据'
           end       if @b <> '' and @b < @c
           begin
              set @a = 'finish'
           end       if @b <> '' and @b >= @c
           begin
              set @a = 'unfinished'
           end       update [Table]
            set a = @a,
                b = @b,
                c = @c
           where
                   ..............end