建立存储过程时提示必须声明变量

ncpuam 2006-08-11 10:44:46
我写的存储过程如下:
CREATE PROCEDURE dbo.isreply
@rootid int,@totalusetable nvarchar(8),@countnum smallint output
AS
begin
if @rootid is null return
select distinct @countnum=count(postuserid)
from @totalusetable
where rootid=@rootid
return
end
go

##################################################

问题是,一直提示必须 @totalusetable
...全文
314 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ncpuam 2006-08-11
  • 打赏
  • 举报
回复
谢谢
Yang_ 2006-08-11
  • 打赏
  • 举报
回复
CREATE PROCEDURE dbo.isreply
@rootid int,@totalusetable nvarchar(8),@countnum smallint output
AS
begin
if @rootid is null return
declare @sql nvarchar(4000)
set @sql=N'
select distinct @countnum=count(postuserid)
from '+@totalusetable+'
where rootid=@rootid'
exec sp_executesql @sql,N'@rootid int,@countnum smallint output',@rootid,@countnum output
return
end
go
WangZWang 2006-08-11
  • 打赏
  • 举报
回复
CREATE PROCEDURE dbo.isreply
@rootid int,
@totalusetable nvarchar(8),
@countnum smallint output
AS
begin
if @rootid is null return

Declare @sql nvarchar(4000)
set @sql='Select @countnum=count(distinct postuserid)
from '+@totalusetable+'
where rootid='+cast(@rootid as nvarchar)
Execute sp_executesql @sql,N'@countnum smallint output',@countnum output
return
end
go

22,206

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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