怎样看存储过程的返回值?

seashoreboy 2003-10-15 11:14:19
这是一个从表中得到一个整数值的存储过程
create proc ZTEP_GET_FIRSTTIME
@id int,
@type int,
@time int output
as
declare @a varchar(1000)
if @type=1
set @a=N'select @time=Min(FixPStartTime) from AA_result'+right(1000+@id,3)
else
set @a=N'select @time=Min(FixPStartTime) from AA_FilterResult'+right(1000+@id,3)
EXEC sp_executesql @a, N'@id int, @time int output',@id,@time output
go

我想看看从time变量返回的值是否正确,请问怎么写测试语句来看?(完整的,能拷贝到查询器中就能执行的)
...全文
48 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
axiaowin 2003-10-17
  • 打赏
  • 举报
回复
set @a=N'select @i=Min(FixPStartTime) from AA_result'+right(1000+@id,3)

开头的N是什么意思?
aierong 2003-10-15
  • 打赏
  • 举报
回复
create proc ZTEP_GET_FIRSTTIME
@id int,
@type int,
@time int output
as
declare @a nvarchar(1000),@par nvarchar(400)
if @type=1
set @a=N'select @t=Min(FixPStartTime) from AA_result'+right(1000+@id,3)
else
set @a=N'select @t=Min(FixPStartTime) from AA_FilterResult'+right(1000+@id,3)
select @par='@t int out'
EXEC sp_executesql @a, @par,@time output
go


--run
declare @t int
execute ZTEP_GET_FIRSTTIME 1,1,@t output
print convert(varchar(100),@t)


@a为nvarchar
seashoreboy 2003-10-15
  • 打赏
  • 举报
回复
怎么执行,报错?
服务器: 消息 214,级别 16,状态 2,过程 sp_executesql,行 11
过程需要参数 '@statement' 为 'ntext/nchar/nvarchar' 类型。
txlicenhe 2003-10-15
  • 打赏
  • 举报
回复
create proc ZTEP_GET_FIRSTTIME
@id int,
@type int,
@time int output
as
declare @a varchar(1000)
if @type=1
set @a=N'select @i=Min(FixPStartTime) from AA_result'+right(1000+@id,3)
else
set @a=N'select @i=Min(FixPStartTime) from AA_FilterResult'+right(1000+@id,3)
EXEC sp_executesql @a, N'@i int output',@time output
select @time
go
pengdali 2003-10-15
  • 打赏
  • 举报
回复
注意过程内部的改动,你原来写错了id不需要写在里面。
pengdali 2003-10-15
  • 打赏
  • 举报
回复
drop proc ZTEP_GET_FIRSTTIME
go
create proc ZTEP_GET_FIRSTTIME
@id int,
@type int,
@time int output
as
declare @a varchar(1000)
if @type=1
set @a=N'select @time=Min(FixPStartTime) from AA_result'+right(1000+@id,3)
else
set @a=N'select @time=Min(FixPStartTime) from AA_FilterResult'+right(1000+@id,3)
EXEC sp_executesql @a, N'@time int output',@time output
go

--调用:
declare @a int
exec ZTEP_GET_FIRSTTIME 23,23,@a output

select @a 结果

34,587

社区成员

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

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