没完全看明白楼主的意图,猜测是要返回临时表中的记录集吧--尽量不要用游标
CREATE proc a_sp_test
@symbol varchar(10),
@tround int,
@rows int
as
declare @t_datetime datetime
declare @count int--取整时间,例如:9:27就取9:25,9:21就取9:20
set @t_datetime = dateadd(minute, -datepart(minute, getdate()) % 5, getdate())select @count = 0create table #tmp (bid decimal, p_time datetime)while @count < @rows
begin
   set @t_datetime = dateadd(minute, -5 * @count, @t_datetime)   insert into #tmp
   select convert(decimal, p_bid) as bid, @t_datetime from hy_data
   where p_item = @symbol and p_time <= @t_datetime
   
   select @count = @count + 1
end-- 楼主应该是要返回这个记录集吧
select bid, p_time from #tmp

解决方案 »

  1.   

    楼主意思好象是返回@rows个记录,从现在往前推每隔@tround秒一笔资料。
    是不是?
      

  2.   

    1。我怎样将多次得到的数据插入到同一个临时表中?create table #临时表 (列1 int,列2 varchar(10))
    insert #临时表 (列1,列2) select 列1,列2 from 你的表 where xx=...
    insert #临时表 (列1,列2) select 列1,列2 from 你的表2
    select * from #临时表
    2。CREATE PROCEDURE titles_cursor @titles_cursor CURSOR VARYING OUTPUT
       这样声明的output型游标的proc有什么用?怎么用?create proc a
    @1 cursor varying out,
    @2 cursor varying out
    as
    declare b cursor local for select * from table1
    declare c cursor local for select * from table1
    open b
    open c
    set @1=b
    set @2=c
    godeclare @a cursor,@b cursorexec a @a out,@b out
    fetch @a
    fetch @b
    fetch @b
    fetch @b
    fetch @aclose @a
    close @bdeallocate @a
    deallocate @bdrop proc a
      

  3.   

    看你这么长的程序看不来了1。我怎样将多次得到的数据插入到同一个临时表中?
    用insert 一次一次插好了
    2。CREATE PROCEDURE titles_cursor @titles_cursor CURSOR VARYING OUTPUT
       这样声明的output型游标的proc有什么用?怎么用?
    我没见过,应该是返回一个记录集吧
      

  4.   

    txlicenhe(马可&不做技术高手)对,就是这个意思
      

  5.   

    amtyuranus(升星中) 
    2。“应该是返回一个记录集吧”
    不是的,是返回一个已经打开的游标。
    pengdali(大力 V3.0) 
    怎么定义,怎么调用我知道,就是不知道什么情况下用比较合适?
      

  6.   

    CREATE    proc a_sp_test
    @symbol varchar(10),
    @tround int,
    @rows int
    asset nocount on  --ADDdeclare @t_datetime datetime --增加注释
    declare @count int
    declare @t_bid varchar(100) --指定长度
    declare @rc int--****要给给变量赋值
    select @count=0,@t_bid=''
    select @t_datetime = convert(datetime,substring(convert(varchar,getdate(),20),1,14) + convert(varchar,(convert(int,substring(convert(varchar,getdate(),20),15,2))/@tround) * @tround))
    select @rc=0
    if (@symbol is not null)
    declare mycursor cursor for 
    select p_bid from hy_data
    where p_item = @symbol   --如果@symbol为null,这里会有错误
      and p_time <= @t_datetime --同样@t_datetime不能为null
    order by p_time desc
    else 
    declare mycursor cursor for 
    select p_bid from hy_data
    where  p_time <= @t_datetime --同样@t_datetime不能为null
    order by p_time desc....
    后面不知道你的目的,你自己看看,一定要做错误处理!!!