我按照一个bit类型的字段=0,取出一个表中的所有数据,希望取出的同时将这个字段设置为1,用来标示这行已经被提取过了,请问怎么做?

解决方案 »

  1.   

    if bit字段=0
    begin 
    "取出操作"
    update 字段=1
    end
    else
    print "已经取出"
      

  2.   

    create proc pc
    as
    select * from tableName where bit_Col=0
    update tableName set bit_Col=1 where bit_Col=0
      

  3.   

    --这样?create proc t 
    as 
    begin 
    declare @i table (...)
    insert into @i 
    select * from table1 where bit =0 update a set bit =1 
    where bit =0select * from @i 
    end
      

  4.   

    用存储过程实现
    create proc test_p @bit bit
    as
    if @bit =0
    begin
    select *from ta where id=0 
    update ta set id=1 where id=0
    end
    else 
    print '无数据'
      

  5.   

    create proc update_column
    as begin tranc
          select * from table where column = 0 
          update table set column_flag = 1 where id in( select id from table where column=0)
          commit 
    end 
      

  6.   

    create proc test_p @bit bit
    as
    if @bit =0
    begin
    select * into # --生成临时表
    from ta where id=0 
    update ta set id=1 where id=0
    select * from #
    end
    else 
    print '无数据'
      

  7.   

    create table T(ID int, bit_col bit)
    insert T select 1, 1
    insert T select 2, 0
    insert T select 3, 1
    insert T select 4, 0
    insert T select 5, 0
    create proc pc
    as 
    select * from T where bit_col=0
    update T set bit_col=1 where bit_col=0
    go
    exec pc
    --result
    ID          bit_col 
    ----------- ------- 
    2           0
    4           0
    5           0(3 row(s) affected)select * from T
    --result
    ID          bit_col 
    ----------- ------- 
    1           1
    2           1
    3           1
    4           1
    5           1(5 row(s) affected)