declare @b int ---用戶定義
set @b=20
declare @a int---條件的數量
select @a=count(sid) as total from [表A] where sid='111'
while(@b-@a>0)
begin
insert into 表a select * from 表a where sid='111'---假如比20大就插入@b-@a條一樣的記錄
end
while(@a-@b>0)
begin
delete from 表a where...-----這裡寫上你想刪除記錄的語句
end
set @b=20
declare @a int---條件的數量
select @a=count(sid) as total from [表A] where sid='111'
while(@b-@a>0)
begin
insert into 表a select * from 表a where sid='111'---假如比20大就插入@b-@a條一樣的記錄
end
while(@a-@b>0)
begin
delete from 表a where...-----這裡寫上你想刪除記錄的語句
end
可是@a如果是18 @b是20,就是插2条吧可是是无限的插入下去了
我在程序里面接受到这个20,如果当管理员把20改成17的时候,就要删除3条记录。
能不能程序提交17的时候,直接用SQL搞定这个问题?
相应的,如果是改成23,我就要插入3条垃圾数据不太明白樓主的意思,怎么理解
set @b=20
declare @a int---外部接受
set @a=18
select @a=count(sid) as total from [表A] where sid='111'
while(@b-@a>0)
begin
insert into 表a select top1 * from 表a ---假如比20大就插入@b-@a條一樣的記錄
end
while(@a-@b>0)--刪除@a-@b條記錄
begin
delete from 表a where checksum(*) in( select checksum(*) from (select top 1 * from 表a)T)
end
set @new=2
declare @total int --条件
select @total=count(sid) from total_s where sid='33'
while(@new-@total>0)
begin
insert into total_s(sid) values('33') --插入
if(@new-@total=0)
break
set @new=@new-1
end
while(@total-@new>0)
begin
set rowcount 1
delete from total_s where sid='33' --删除
if(@total-@new=0)
break
set @total=@total-1
end
我在程序里面接受到这个20,如果当管理员把20改成17的时候,就要删除3条记录。
能不能程序提交17的时候,直接用SQL搞定这个问题?
相应的,如果是改成23,我就要插入3条垃圾数据"
程序如何得到这个20 ? 通过recordset???
如果提交17或者23这种修改? 楼主的这种recordset根本就是不可更新的recordset,当然没有修改的可能
所以关键的问题不是如何处理数据,而是楼主如何实现与用户的交互.