如何 return 过程中的一个结果集
how to return one result set from procedure
我正在尝试制作一个程序 return 使用旧版本的 Sybase 随机选择行。
这是我到现在为止想到的。似乎每一行都 return 在其自己的结果集中编辑。
如何 "group" 单个结果集中的所有选定行?
create procedure samplerecords
@pcttosample float as
declare @val varchar(255)
declare @cointoss float
declare curs cursor for
select foo from bar
at isolation read uncommitted
open curs
fetch curs into @val
while (@@sqlstatus != 2)
begin
select @cointoss=rand()*100
if @cointoss <= @pcttosample
select @val
fetch curs into @val
end
close curs
return
如果您需要坚持使用 rand() 函数的方法,则只需将值列表插入临时 table,然后 select结束。
create table #t (val varchar(255) not null) -- add at the beginning
...
insert into #t (val) values (@val) -- replaces the select @val
...
select val from #t -- add at the end
我正在尝试制作一个程序 return 使用旧版本的 Sybase 随机选择行。
这是我到现在为止想到的。似乎每一行都 return 在其自己的结果集中编辑。
如何 "group" 单个结果集中的所有选定行?
create procedure samplerecords
@pcttosample float as
declare @val varchar(255)
declare @cointoss float
declare curs cursor for
select foo from bar
at isolation read uncommitted
open curs
fetch curs into @val
while (@@sqlstatus != 2)
begin
select @cointoss=rand()*100
if @cointoss <= @pcttosample
select @val
fetch curs into @val
end
close curs
return
如果您需要坚持使用 rand() 函数的方法,则只需将值列表插入临时 table,然后 select结束。
create table #t (val varchar(255) not null) -- add at the beginning
...
insert into #t (val) values (@val) -- replaces the select @val
...
select val from #t -- add at the end