create procedure [拥有者.]名[;程序编号] [(参数#1,…参数#1024)] [with {recompile | encryption | recompile, encryption} ] [for replication] as 程序行 其中存储过程名不能超过128个字。每个存储过程中最多设定1024个参数 (sql server 7.0以上版本),参数的使用方法如下: @参数名 数据类型 [varying] [=内定值] [output] 每个参数名前要有一个“@”符号,每一个存储过程的参数仅为该程序内部使用,参数的类型除了image外,其他sql server所支持的数据类型都可使用。
declare @mycounter int
set @mycounter = 0 /*设置变量*/
while (@mycounter begin
waitfor delay '000:00:10' /*延迟时间10秒*/
insert into time_by_day
(time_id, the_date, the_year, month_of_year, quarter, day_of_month)
select top 1 time_id + 1 as time_id, the_date + 1 as the_date, year(the_date + 1)
as the_year, month(the_date + 1) as month_of_year, { fn quarter(the_date + 1)
} as quarter, day(the_date + 1) as day_of_month
from time_by_day
order by time_id descset @mycounter = @mycounter + 1
end
用游标吧
declare @a int,@b int
declare ccc cursor for select * from test where id>@id
open ccc
fetch next from ccc into @a,@b
while (@@fetch_status=0)
begin
.......
end
close ccc
declare ccc(这个操作看看别的系统存储过程怎么写的 记不太清了 每次都是copy的)大概就是这样 不知道语法有没有错误 最近一段时间没用sqlserver了 看看系统存储过程就能明白怎么用cursor了