请教用ASP向存储过程传递参数(表名)为什么出错?请大家帮忙解决!谢谢!代码如下:

leetsing 2003-04-09 11:24:08
在ASP中执行
SqlStr="exec stat_msgdb_step1 "&tablename&","&startday&","&endday&","&"1"
set rs = cnn.Execute(SqlStr)
报错

存储过程:
CREATE PROCEDURE stat_msgdb_step1
(@tablename char,@startday int,@endday int,@feeflag int)
AS
declare @sqlstr char(500)

if @feeflag=1
begin
select serviceid,count(*) as counts,count(distinct srctermid) as hushu
from @tablename where convert(int,feecode)<>0 and srctermid not in (select mobile from usercode) and
convert(int,substring(createtime,1,8))>=@startday, 1) and convert(int,substring(createtime,1,8))<=@endday, 1) and
convert(int,feetype)<>3 group by serviceid order by serviceid

end
if @feeflag=0
……
……
...全文
6 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
leetsing 2003-04-09
斑竹
我的问题没有人能解答,看来得向你求助啦!
回复
bflyh666 2003-04-09
try:
SqlStr="exec stat_msgdb_step1 '"& tablename &"',"& startday &","& endday &","& "1"
回复
leetsing 2003-04-09
大哥,没这么复杂吧!
我的存储过程才查询分析器里执行没问题
用asp执行
SqlStr="exec stat_msgdb_step1 "&tablename&","&startday&","&endday&","&"1"
set rs = cnn.Execute(SqlStr)

set rs = cnn.Execute(SqlStr)
报错
回复
leimin 2003-04-09
对ADO调用有输入和输出参数的SP,要用COMMAND对象,
you can try


...
conn.open
set au_adocmd=server.CreateObject("adodb.command")
au_adocmd.CommandText="stat_msgdb_step1"
au_adocmd.ActiveConnection=constr
au_adocmd.CommandType=adCmdStoredProc '4

conn.BeginTrans
set p=au_adocmd.Parameters
p.Append au_adocmd.CreateParameter("RETURN_VALUE",3,4)
p.Append au_adocmd.CreateParameter("@tablename",3,1)
p.Append au_adocmd.CreateParameter("@startday",3,1)
p.Append au_adocmd.CreateParameter("@endday",3,1)
p.Append au_adocmd.CreateParameter("@tag",3,1)

au_adocmd("@tablename") =ltrim(tablename)
au_adocmd("@startday") =startday
au_adocmd("@endday") =endday
au_adocmd("@tag") =1

au_adocmd.Execute
returnvalue=au_adocmd.Parameters("RETURN_VALUE").Value

...
回复
相关推荐
发帖
疑难问题
创建于2007-09-28

2.1w+

社区成员

MS-SQL Server 疑难问题
申请成为版主
帖子事件
创建了帖子
2003-04-09 11:24
社区公告
暂无公告