存储过程中用execute sql语句怎么得到这个sql语句的返回值啊

liujun999999 2004-06-08 09:40:44
set @tempsql='select count(papername) from paper where papername='''+@papername+''''
sql语句是这样的
...全文
1043 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
pbsql 2004-06-10
  • 打赏
  • 举报
回复
exec sp_executesql要求SQL语句是nvarchar型,execute则无此要求,所以前面没有错

改吧
liujun999999 2004-06-10
  • 打赏
  • 举报
回复
shenen(真的愛你) 我想不是这样的吧
因为前面的sql语句执行都没有错误的啊
liujun999999 2004-06-10
  • 打赏
  • 举报
回复
谢谢大家
问题我自己已经解决
netying 2004-06-10
  • 打赏
  • 举报
回复
mark.
minjunjie 2004-06-09
  • 打赏
  • 举报
回复
楼主这个问题:服务器: 消息 214,级别 16,状态 2,过程 sp_executesql,行 16
过程需要参数 '@statement' 为 'ntext/nchar/nvarchar' 类型。
我今天就遇到了,不知何意,往高人指点sp_executesql的用法,一起顶'"'
shenen 2004-06-09
  • 打赏
  • 举报
回复
declare @tempsql varchar(1000),@re int
=>
declare @tempsql nvarchar(1000),@re int

liujun999999 2004-06-09
  • 打赏
  • 举报
回复
create proc paperbuild @papername char(200), @subject char(50), @xzt int,@xztn int,@tkt int,@tktn int,@pdt int,@pdtn int,
@wdt int,@wdtn int as
/*选择题生成部分*/
declare @bxzt int
declare @tempsql varchar(1000),@re int
set @bxzt=@xzt/2
select @bxzt
set @tempsql= 'insert into paper(question1,q_type,right_answer,option1,difficulty) select top '+str(@bxzt)+' question1,q_type,right_answer,option1,difficulty from question where q_type=''选择题'' and subject='''+@subject+''''
execute(@tempsql)
set @tempsql='update paper set papername='''+@papername+''' where papername is null'
execute(@tempsql)
select @tempsql
declare @lxzt int,@lsnd int
set @lxzt=@xzt-@bxzt
set @tempsql='select '+str(@re)+'=count(papername) from paper where papername='''+@papername+''''
exec sp_executesql @tempsql,N'@re int out',@re out
set @lsnd=@re
if @lsnd>@xztn
select 'da'
else
select 'xiao'
go
这个是我存储过程的全部内容了
各位帮忙看看
错误就是上面写的那个
zheninchangjiang 2004-06-09
  • 打赏
  • 举报
回复
这样存储过程创建的时候没有错误
但是调用的时候它说
服务器: 消息 214,级别 16,状态 2,过程 sp_executesql,行 16
过程需要参数 '@statement' 为 'ntext/nchar/nvarchar' 类型。
救救我吧

--那是你程序的错误,DELPHI不会,但如果你用的是ADO,你必须用command对象,并给command对象添加一个名为@statement的参数(parameter),commandtext为stored procedure
执行一下就行了,返回值就是那个参数的值
jzzgood 2004-06-09
  • 打赏
  • 举报
回复
用它试一下:
select @tempsql=count(papername) from paper where papername='''+@papername+''''

pbsql 2004-06-09
  • 打赏
  • 举报
回复
也不对,你还是把整个存储过程帖出来吧
pbsql 2004-06-09
  • 打赏
  • 举报
回复
你的字段papername不是nvarchar类型吧?若是报错就是正确的
pbsql 2004-06-09
  • 打赏
  • 举报
回复
16行 是哪一句?
liujun999999 2004-06-09
  • 打赏
  • 举报
回复
可是我现在只是在查询分析器里调用
上面的程序而且是写在一个存储过程中
我是在asp中调用这样的代码
但是现在查询分析器的这都没有通过
zjcxc 元老 2004-06-08
  • 打赏
  • 举报
回复
declare @tempsql nvarchar(4000),@re int
set @tempsql='select @re=count(papername) from paper where papername='''+@papername+''''

exec sp_executesql @tempsql,N'@re int out',@re out
select 结果=@re
Communism 2004-06-08
  • 打赏
  • 举报
回复
用 select * from exec(@tempsql)
liujun999999 2004-06-08
  • 打赏
  • 举报
回复
顶上去
liujun999999 2004-06-08
  • 打赏
  • 举报
回复
declare @tempsql nvarchar(4000),@re int
set @tempsql='select @re=count(papername) from paper where papername='''+@papername+''''

exec sp_executesql @tempsql,N'@re int out',@re out
select 结果=@re

这样存储过程创建的时候没有错误
但是调用的时候它说
服务器: 消息 214,级别 16,状态 2,过程 sp_executesql,行 16
过程需要参数 '@statement' 为 'ntext/nchar/nvarchar' 类型。
救救我吧

34,592

社区成员

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

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