declare @orcount int -- 满足条件的订单数量; declare @orderNum nvarchar(50) -- 订单号; declare @orderSec nvarchar(50) -- 景点名; declare @orderDate nvarchar(50) -- 预约日期; declare @erroDate nvarchar(50) -- 错误的日期; set @erroDate = '2016-16' --查询出日期; select @orcount = count(id) from [db].[dbo].[dindanjd] where [bookingdate] = @erroDate while @orcount > 0 begin select top 1 percent @orderNum=id, @orderSec = [name] from [db].[dbo].[dindanjd] where [bookingdate] = @erroDate select @orderDate = [bookingdate] from [db2].[dbo].[dindanjd] where id = @orderNum and [name] = @orderSec update [db].[dbo].[dindanjd] set [bookingdate] = @orderDate where id = @orderNum and [name] = @orderSec set @orcount = @orcount-1 end