日期:2014-05-19  浏览次数:20477 次

存储过程出错!!
CREATE   PROCEDURE   过程名
@rowscount   int   output,
as
set   @rowscounSQL   =   'select   @rowscount=count(Used_ID)   From   Used_Auto '
exec(@rowscounSQL)

出错如下
服务器:   消息   137,级别   15,状态   1,行   1
[Microsoft][ODBC   SQL   Server   Driver][SQL   Server]必须声明变量   '@rowscount '。


------解决方案--------------------
CREATE PROCEDURE 过程名
@rowscount int output,
as
set @rowscounSQL = 'select ' +@rowscount + '=count(Used_ID) From Used_Auto '
exec(@rowscounSQL)

應該要這樣
------解决方案--------------------
CREATE PROCEDURE 过程名
@rowscount int output
as
declare @rowscounSQL Nvarchar(2000)
set @rowscounSQL = 'select @rowscount=count(Used_ID) From Used_Auto '
EXEC sp_executesql @rowscounSQL, N '@rowscount int Output ',@rowscount Output