存储过程问题 如何让 exec执行的SQL语句中的数据赋值给存储过程中的 OUTPUT变量?
create proc sp_test
@KW nvarchar(50),
@PT int=100,
@PC int=0 output
as
declare @sql as nvarchar(2000)
set @sql='select top '+cast(@PT as nvarchar(10))+' @PC=count(1),t.id,t.title,t.pic from tupian t inner join ContainsTable(tupian,*,'''+ @KW +''') t2 on t.[id]=t2.[key] where t.isshow=1 order by t2.rank desc'
exec(@sql)
return
go
declare @f int
execute sp_test 10,@f output
print @f
go
------------------------------------------------------------------------
错误信息:
服务器: 消息 137,级别 15,状态 1,行 1
必须声明变量 '@PC'。
-------------------------------------------------------------------------
我想select top 的同时用 count统计结果集 并将结果结数通过output 返回。
直接用 select top @PT @PC=count(1),t.id,t.title,t.pic from tupian t inner join ContainsTable(tupian,*,@KW) as t2 on t.[id]=t2.[key] where t.isshow=1 order by t2.rank desc 不行
用了全文索引
用上面的写法执行的SQL 有不能把存储过程中的@PC 赋值。 这我该怎么实现?