日期:2014-05-18  浏览次数:20640 次

执行存储过程出错
执行存储过程出错
CREATE procedure xs_gzxx
@TableName varchar(30)
as
exec('select count(*) as zts from ['+ @TableName + ']')
exec('select count(*) as yts from ['+ @TableName + '] where rgl>0')
exec('select count(*) as wts from ['+ @TableName + '] where rgl=0')
GO
在查询分析器执行
declare @TableName varchar(30) set @TableName='F2201252' 
得到zts,yts,wts
一切正常
在 vb6.0 command按钮中执行
sjsrGrade.rsDK1 "declare @TableName varchar(30) set @TableName='F2201252'"
text1.text=str(sjsrGrade.rs1!zts)
text2.text=str(sjsrGrade.rs1!yts)
text3.text=str(sjsrGrade.rs1!wts)
只能显示第一条zts
后面二条出错信息为:
实时错误‘3265’
在对应所需名称或序数的集合中,未找到项目

------解决方案--------------------
你选出来的是三行嘛,当然是错了,应该是三个记录集才对呀,而不是一个记录集中的三条记录。。。
------解决方案--------------------
SQL code

CREATE procedure xs_gzxx
@TableName varchar(30)
as
if object_id('tempdb..#t') is not null drop table #t
create table #t(zts int,yts int,wts int)
declare @sql nvarchar(max)
select @sql='insert #t(zts) select (select count(1) from '+@TableName+');
update #t set yts=(select count(1) from '+@TableName+' where rgl>0);
update #t set wts=(select count(1) from '+@TableName+' where rgl=0);'
exec(@sql)
select * from #t
go