declare @a int
set @a=1
while @a<=300
begin
if @a in (select id from archive_z)
update archive_z set records =(select count(*) from archiveRecoder_z where archiveid=@a) where id=@a
set @a=@a+1
end
其他。。
USE [snav]
GO
/****** Object: StoredProcedure [dbo].[sp_bendi] Script Date: 03/25/2011 14:21:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[sp_bendi]
@city varchar(20),
@pro varchar(20)
AS
DECLARE @count int
DECLARE @row int
declare @sql varchar(300),@from varchar(50)
set @row=8
set @from=' * from zz_url where sortid=1 and city=''' + @city +''''
set @count=(select count(id) from zz_url where sortid=1 and city=@city)
declare @topN varchar(3),@topM varchar(3)
if @count<8
begin
select @topN=@count,@topM=@row-@count
set @sql='select * from (select top ' + @topN + @from
set @sql=@sql+' union all select * from ( select top ' + @topM + ' * from zz_url where sortid=1 and province=''' + @pro + ''' order by newid())a )p'
end
else if @count=8
set @sql='select top 8'+ @from
else
begin
DECLARE @size int,@sindex int,@movetop varchar(3)
set @size=(@count+@row-1)/@row
set @sindex=datename(dy,getdate())%@size
select @topN=@row,@movetop=@sindex*@row
set @sql='select top ' + @topN + @from
set @sql= @sql + ' and id not in (select top '+ @movetop +' id from zz_url where sortid=1 and city=''' + @city + ''' )'
if @sindex=(@size-1) and @count%@row<>0
begin
select @topM=@row-@count%@row
set @sql=@sql+' union all select top ' + @topM + @from
end
end
exec(@sql)