关于存储过程中参数的问题
存储过程中:
DECLARE @T08_COUNT int
SET @T08_COUNT = 0
DECLARE @T08_COUNT_SQL varchar(300)
SET @T08_COUNT_SQL = 'SELECT @T08_COUNT = count(*) FROM [TABLE_NAME] WHERE [ID] = ' ' ' + @ID + ' ' ' and [KEY_NMM] = ' 'REKI_LIST ' ' '
EXEC (@T08_COUNT_SQL)
执行存储过程,却抱错说 @T08_COUNT 没有定义? 但是上面定义了呀!
不明白?
求助!
[解决办法]
DECLARE @T08_COUNT int
SET @T08_COUNT = 0
DECLARE @T08_COUNT_SQL Nvarchar(300)--改為Nvarchar
SET @T08_COUNT_SQL = 'SELECT @T08_COUNT = count(*) FROM [TABLE_NAME] WHERE [ID] = ' ' ' + @ID + ' ' ' and [KEY_NMM] = ' 'REKI_LIST ' ' '
EXEC sp_executesql @T08_COUNT_SQL,N '@T08_COUNT int output ',@T08_COUNT output --使用sp_executesql
[解决办法]
create proc test_Proc @ID int
as
set quoted_identifier off
DECLARE @T08_COUNT int
SET @T08_COUNT = 0
DECLARE @T08_COUNT_SQL nvarchar(300)
SET @T08_COUNT_SQL = "SELECT @T08_COUNT = count(*) FROM [TABLE_NAME] WHERE [ID] = ' " + ltrim(@ID) + " ' and [KEY_NMM] = 'REKI_LIST ' "
exec sp_executesql @T08_COUNT_SQL, '@T08_COUNT int output ',@T08_COUNT output
select @T08_COUNT