set @edate = inowork from inwork where id = @id
if @edate is null
   update inwork set inwork = getdate() where id = @id
else
   update inwork set outwork = getdate() where id = @id

解决方案 »

  1.   

    插入:
    INSERT INTO inwork (ID, inwork) VALUES  (@ID, getdate())
      

  2.   

    我写的:
    create proc kq_taday_insert
    @id nvarchar (10),
    @a datetime
    as
    select @a=inwork from inwork where (id=@id) and (inwork=getdate())
       if @a is null--签到
    insert into inwork (id,inwork) values(@id,getdate())
       else --签退
       update inwork set outwork=getdate() where id=@id
    对吗?
      

  3.   

    运行exec kq_taday_insert 9,'2003-04-11 23:50:48.480'不行啊!!
      

  4.   

    kq_taday_insert的第一个参数@id是字符型的,不能使用整形
    可以根据你的表设计做适当的修改
      

  5.   

    create proc kq_taday_insert
    @id nvarchar (10),
    @a datetime
    as
    select @a=inwork from inwork where (id=@id) and convert(char(10),inwork,111)=convert(char(10),getdate(),111)
       if @a is null--签到
    insert into inwork (id,inwork) values(@id,getdate())
       else --签退
       update inwork set outwork=getdate() where id=@id
      

  6.   

    select @a=inwork from inwork where (id=@id) and  datediff(dy,inwork,getdate())<1
      

  7.   

    运行exec kq_taday_insert 9,'2003-04-11 23:50:48.480'后应添加一条记录,没有啊!!