删除蓝钻副卡.sql 627 B

123456789101112131415161718
  1. -- 说明:只要修改use [db]中的数据库名即可;
  2. use [db]
  3. declare @count int
  4. declare @memberid nvarchar(50)
  5. -- 查询出要删除的蓝钻会员,将卡号保存到临时表;
  6. select distinct memberno into memberno_temp from membercard2blue where memberno not in(select memberno from membermanageblue)
  7. print '开始删除'
  8. -- 逐个删除;
  9. select @count = count(*) from memberno_temp
  10. while ( @count > 0 )
  11. begin
  12. select top 1 @memberid = memberno from memberno_temp
  13. delete from membercard2blue where memberno = @memberid
  14. delete from memberno_temp where memberno = @memberid
  15. select @count = count(*) from memberno_temp
  16. end
  17. -- 删除临时表;
  18. drop table memberno_temp