这个问题我现在也头疼!! 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记录集?? %>
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记录集??
%>
set nocount on
如果不行,我就over了
recordset.open (exec 存储过程名 参数1,参数2,…………),connection,,,,adcmdtable
drop table #temptable