sql server 存储过程里我无法获得记录集(select from 一张临时表)

javanow 2001-08-26 12:30:43
sql server 存储过程里我无法获得记录集(select from 一张临时表)
在存储过程里我用select * from #tempTable
然后我用
set rs=cm.execute()
我发现无法获得记录集( rs.fields.count=0)
但是我将 select * from #tempTable 改为一张永久表如select * from UserList
就可以获得记录集。
请高手帮忙 
...全文
158 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
kurtcobain 2002-01-29
  • 打赏
  • 举报
回复
这个问题我现在也头疼!!
cREATE proc select_prize
@begindate datetime,
@enddate datetime,
@companyaccount [varchar](200),
@content [varchar](100),
@m int ,
@n int
as
declare @csql varchar(600)
--declare @csql1 char(600)
if @m<>""
begin
set @csql=' select top '+cast(@m as nchar)+' callnumber , times = count(callnumber) into #temptable from OUUpSM_Original
where success=1 and content="'+@content+'" and compaccount='''+@companyaccount +''' and receivetime between '' '+cast(@begindate as nchar)+''' and '''+ cast(@enddate as nchar) +''' group by callnumber order by times desc select top '+cast(@n as nchar)+ ' * from #temptable order by newid() '
end
if @m="" and cast(@n as nchar)<>''''
begin
set @csql=' select callnumber , times = count(callnumber) into #temptable from OUUpSM_Original
where success=1 and content="'+@content+'" and compaccount='''+@companyaccount +''' and receivetime between '' '+cast(@begindate as nchar)+''' and '''+ cast(@enddate as nchar) +''' group by callnumber order by times desc select top '+cast(@n as nchar)+ ' * from #temptable order by newid() drop table #temptable '
end
--print @csql
exec (@csql)
GO


我的存储过程看起来复杂,其实就是从一个表A中取出符合条件的纪录,插入到一个临时表#temptable中,然后再从#temptable中取出符合所要的纪录,然后再把临时表释放掉,
在asp中调用如下:
<%
set rsinsert=server.CreateObject("adodb.recordset")
str="exec select_prize '"& begint &"','"&endt&"','"&CompanyAccount&"','"&content&"',"&totalnumber&","&pplnum
response.write str
rsinsert.Open str,connectstring,3,1
Response.Write "<br>"& rsinsert.RecordCount
可什么也没有输出,但是把输出的str在query中执行后,有两条纪录
到底是为什吗?我最后发现是因为临时表的问题
如果说是因为用到了临时表,那我应该怎么办???怎吗改????才能返回rs记录集??


%>
蓝天 2002-01-29
  • 打赏
  • 举报
回复
去掉
drop table #temptable
kurtcobain 2002-01-29
  • 打赏
  • 举报
回复
加了set nocount on ,可返回结果是-1
kurtcobain 2002-01-29
  • 打赏
  • 举报
回复
不行,我加了set nocount on 可结果是-1,到地位什吗呀???
zcflion 2002-01-29
  • 打赏
  • 举报
回复
对了少一个应该是这样的
recordset.open (exec 存储过程名 参数1,参数2,…………),connection,,,,adcmdtable
zcflion 2002-01-29
  • 打赏
  • 举报
回复
用记录集来做存储过程的执行调用试一下,如下:

recordset.open (存储过程名 参数1,参数2,…………),connection,,,,adcmdtable
javanow 2002-01-29
  • 打赏
  • 举报
回复
在as后面加上
set nocount on
如果不行,我就over了
18502232832 2001-08-27
  • 打赏
  • 举报
回复
应该不会吧,你把程序贴出来看看!
javanow 2001-08-26
  • 打赏
  • 举报
回复
忘 了说是通过asp程序无法获得
Corny 2001-08-26
  • 打赏
  • 举报
回复
可以获得,我一直这么做

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧