从备份数据库中还原订单套系类别字段.sql 863 B

1234567891011121314151617181920212223242526272829303132
  1. use master
  2. -- 第一步,查找出所有无套系类别的订单号,并保存;
  3. select identity(int,1,1) as autoid,id into [db].[dbo].[dindan_temp] from [db].[dbo].[dindan] where [txtype] = NULL or [txtype] = ''
  4. go
  5. -- 第二步,更新空的套系类别订单;
  6. declare @count int
  7. declare @index int
  8. declare @order nvarchar(50)
  9. declare @txtype nvarchar(50)
  10. select @count = count(id) from [db].[dbo].[dindan_temp]
  11. print @count
  12. set @index = 1
  13. print @index
  14. while @index <= @count
  15. begin
  16. select @order = id from [db].[dbo].[dindan_temp] where autoid = @index
  17. select @txtype = [txtype] from [20150].[dbo].[dindan] where id = @order
  18. update [db].[dbo].[dindan] set [txtype] = @txtype where id = @order
  19. set @index = @index + 1
  20. end
  21. go
  22. -- 第三步,删除表;
  23. drop table [db].[dbo].[dindan_temp]
  24. go
  25. --查询有无套系类型空的订单;
  26. -- select [txtype],* from [db].[dbo].[dindan] where [txtype] = NULL or [txtype] = ''