没完全看明白楼主的意图,猜测是要返回临时表中的记录集吧--尽量不要用游标
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
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
解决方案 »
- 上周给公司将SQL2000升级到SQL2005,升级后出现了一个比较大的问题
- 高分请教一个简单的sql安装问题
- 请教一个数据库内存的问题
- 新人求指点啊。。怎么把表中字段有重复的值修改掉呢
- oracle 中的NVL()函数在sql server中对应的是什么函数啊
- SQL如何根据上一行的值来计算这一条的值
- 我的sqlserver2000个人版安装不上,出错如何解决
- 求助:在非工作时间不得修改数据的问题
- IIS5的ASP连不上Access数据库,能连上SQL SERVER,什么原因?
- sql server 的图片导入问题!!
- 更新数据表问题, 求救各位大哥.
- 一次性计算表内多个分类的总记录数,怎么写sql?是不是很有难度?
是不是?
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
用insert 一次一次插好了
2。CREATE PROCEDURE titles_cursor @titles_cursor CURSOR VARYING OUTPUT
这样声明的output型游标的proc有什么用?怎么用?
我没见过,应该是返回一个记录集吧
2。“应该是返回一个记录集吧”
不是的,是返回一个已经打开的游标。
pengdali(大力 V3.0)
怎么定义,怎么调用我知道,就是不知道什么情况下用比较合适?
@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....
后面不知道你的目的,你自己看看,一定要做错误处理!!!