if bit字段=0 begin "取出操作" update 字段=1 end else print "已经取出"
create proc pc as select * from tableName where bit_Col=0 update tableName set bit_Col=1 where bit_Col=0
--这样?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
用存储过程实现 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 '无数据'
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
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 '无数据'
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)
begin
"取出操作"
update 字段=1
end
else
print "已经取出"
as
select * from tableName where bit_Col=0
update tableName set bit_Col=1 where bit_Col=0
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
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 '无数据'
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
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 '无数据'
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)