下面那个@gs的参数不认啊,快快啊联系我qq14562080 CREATE PROCEDURE pd_ht (@sjbh CHAR (14),@gs int,@fz float,@lxbh char(2)) AS /*@sjbh CHAR (14)试卷编号,@gs int,个数@fz float,分值@lxbh char(2)试题类型*/ declare mycursor cursor global scroll static for select top @gs id from t_zpstkglb where lxbh=@lxbh order by newid() open mycursor declare @stbh char(14) fetch next from mycursor into @stbh while (@@fetch_status=0) begin insert t_zpsjb(id,stbh,fz) values(@sjbh,@stbh,@fz) fetch next from mycursor into @stbh end close mycursor deallocate mycursor
top 后面不能用变量啊,将定义游标的语句变成字符串,放进EXEC()中运行也可以产生游标: DeClare @Scur varchar(2000)
Set @Scur='declare mycursor cursor global scroll static for select top '+Str(@gs)+' id from t_zpstkglb where lxbh=''+@lxbh+'' +' order by newid()' Exec(@Scur)
不过觉得您的order by newid() 怪怪的!
----------------------------------------------
-