SQL存储过程报错Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar',请教高手
@monthvarchar(20),--年月@daytotalint--月天数ASdeclare@logtablevarchar(20)declare@icountint...
@month varchar(20), --年月
@daytotal int --月天数
AS
declare @logtable varchar(20)
declare @icount int
declare @sumtemp int
declare @sum int
declare @sql varchar(50)
set @logtable=@month+'00'
set @icount=0
set @sumtemp=0
set @sum=0
begin
while(@icount<=@daytotal)
begin
select @logtable=@logtable+1
set @sql=N'select @sumtemp=count(*) from log@logtable where content like ''感谢使用%'' '
exec sp_executesql @sql
select @sum=@sum+@sumtemp
end
end
运行报错Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar',大家帮我看看是为什么呢?
经过simenyu提醒,修改后原先的错误没有了,主题部分改为
select @logtable=@logtable+1
set @sql=N'select @sumtemp=count(*) from log@logtable where content like ''感谢使用%'' '
exec sp_executesql @sql,N'@sumtemp int out,@logtable int ',@sumtemp output
select @sum=@sum+@sumtemp
但是现在存储过程后没有结果,终止后出现Incorrect syntax near 'where'.是为什么呢? 展开
@daytotal int --月天数
AS
declare @logtable varchar(20)
declare @icount int
declare @sumtemp int
declare @sum int
declare @sql varchar(50)
set @logtable=@month+'00'
set @icount=0
set @sumtemp=0
set @sum=0
begin
while(@icount<=@daytotal)
begin
select @logtable=@logtable+1
set @sql=N'select @sumtemp=count(*) from log@logtable where content like ''感谢使用%'' '
exec sp_executesql @sql
select @sum=@sum+@sumtemp
end
end
运行报错Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar',大家帮我看看是为什么呢?
经过simenyu提醒,修改后原先的错误没有了,主题部分改为
select @logtable=@logtable+1
set @sql=N'select @sumtemp=count(*) from log@logtable where content like ''感谢使用%'' '
exec sp_executesql @sql,N'@sumtemp int out,@logtable int ',@sumtemp output
select @sum=@sum+@sumtemp
但是现在存储过程后没有结果,终止后出现Incorrect syntax near 'where'.是为什么呢? 展开
展开全部
出现闹雹这个提示,是因为变量@sql的类型有误,声明时应该写成nvarchar,如:
declare @sql nvarchar(50)
补充:
过程参橘宏数错误,试试改成这样
select @logtable=@logtable+1
set @sql=N'select @sumtemp=count(*) from log'+@logtable+' where content like ''感液伍帆谢使用%'' '
exec sp_executesql @sql,N'@sumtemp int out',@sumtemp output
select @sum=@sum+@sumtemp
declare @sql nvarchar(50)
补充:
过程参橘宏数错误,试试改成这样
select @logtable=@logtable+1
set @sql=N'select @sumtemp=count(*) from log'+@logtable+' where content like ''感液伍帆谢使用%'' '
exec sp_executesql @sql,N'@sumtemp int out',@sumtemp output
select @sum=@sum+@sumtemp
展开全部
set @sql=N'select @sumtemp=count(*) from log@logtable where content like ''感碧灶祥谢使用%'' '
改成辩梁
set @sql=N'select @sumtemp=count(*) from log@logtable where content like ''%感悔搏谢使用%'' '
改成辩梁
set @sql=N'select @sumtemp=count(*) from log@logtable where content like ''%感悔搏谢使用%'' '
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询