请问sp_executesql的问题,如何给你一变量赋值

whmjw 2005-05-12 07:15:15
declare @sql varchar(1000)
declare @price float

declare @some int
set @some=2
declare @temp varchar(20)
set @temp=cast(@some as varchar(2))
set @sql='select @price1=hour'+@temp +' from sn_snroomprice where tablecode=''1002'''
--exec(@sql),@price output
EXECUTE sp_executesql @sql,N'@price1 float output',@price output--这里报错
print @price

这样的语句执行总是报错,

服务器: 消息 214,级别 16,状态 2,过程 sp_executesql,行 10
过程需要参数 '@statement' 为 'ntext/nchar/nvarchar' 类型。

为什么???
...全文
167 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
whmjw 2005-05-12
  • 打赏
  • 举报
回复
晕呀,这么简单,结贴
paoluo 2005-05-12
  • 打赏
  • 举报
回复

declare @sql Nvarchar(1000) --改为Nvarchar
declare @price float
declare @some int
set @some=2
declare @temp varchar(20)
set @temp=cast(@some as varchar(2))
set @sql='select @price1=hour'+@temp +' from sn_snroomprice where tablecode=''1002'''
--exec(@sql),@price output
EXECUTE sp_executesql @sql,N'@price1 float output',@price output--这里报错
print @price

34,590

社区成员

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

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