sql id循环设置字段值

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值