求一个SQL语句 表Aid name ok1 aaa 02 bbb 13 ccc 04 ddd 0当我更新id=3的记录时ok=1 则id=2的ok就为0即ok字段只能有一条记录为1 。这个用一个SQL语句能否搞定? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 update aset ok=1where id=3goupdate aset ok=0where id=2 update a set ok=1 from tableA a where a.id not in (select id from tableA where ok=1)) update a set ok=1 where id=3 update a set ok=0 where id<>3 update aset ok=case when id=3 then 1 else 0 end update a set ok=0 from tableA a where a.id <> (select id from tableA where ok=1) Yang_(扬帆破浪) 的方法好。多谢。结帖 先建个存储过程create procedure test (@id int)as begin update BB set ok=1 where id=@id update BB set ok=0 where id<>@id end 然后一条语句搞定^-^exec test 3 求助 sql 语句 单表查询结果自动添加序号 如何修改表中某字段默认值? 我们自己用VB+(SQL SERVER 2000)或MSDE编写了单机版应用程序交给客户使用,同时也必须将mdf数据库一起交给客户,假设我们让很多用户都 求怎样更新排列语句? 在安装sql2008的时候遇到“MOF 编译器无法连接 WMI 服务器”的问题如何解决? 执行sqlserver脚本问题,高手们请帮忙! sqlserver中对应ORACLE序列对象的机制是什么? sql能不能在选出的数据中随机选取n个出来? 关于安装SQL Server 问个统计的问题 一条尽量去重的sql语句,请大家指点
set ok=1
where id=3
goupdate a
set ok=0
where id=2
update a set ok=0 where id<>3
set ok=case when id=3 then 1 else 0 end
create procedure test (@id int)
as
begin
update BB set ok=1 where id=@id
update BB set ok=0 where id<>@id
end
然后一条语句搞定^-^
exec test 3