ALTER PROCEDURE [dbo].[P_OA_JudgeFromValueWhere]
@FromNo nvarchar(500),
@strSql nvarchar(500),
@ErrorCount int OUTPUT
AS
BEGIN
EXEC ('SELECT '+@ErrorCount+'=COUNT(*) FROM V_OA_FromValueInfo WHERE FromNo='+@FromNo+' and '+@strSql);
IF @@ERROR > 0
BEGIN
SET @ErrorCount = -1;
RETURN
END
END
那里有问题,编译能过,执行报错 : '=' 附近有语法错误。
你的语法不对,不能这么输出参数。得用这个
sp_executesql [@stmt =] stmt
[
{, [@params =] N'@parameter_name data_type [,...n]' }
{, [@param1 =] 'value1' [,...n] }
]
补充示例:
DECLARE @Count INT
EXECUTE SP_EXECUTESQL N'SELECT @TempCount = COUNT(*) FROM SPT_MONITOR',
N'@TempCount INT OUTPUT',
@TempCount =@Count OUTPUT
PRINT @Count
EXEC ('SELECT '+cast(@ErrorCount as nvarchar(10))
+'=COUNT(*) FROM V_OA_FromValueInfo WHERE FromNo='
+@FromNo+' and '+@strSql);
注意@ErrorCount是整型
create PROCEDURE [dbo].[P_OA_JudgeFromValueWhere]
@FromNo nvarchar(500),
@strSql nvarchar(500),
@ErrorCount int OUTPUT
AS
BEGIN
declare @sqlt nvarchar(1000)
set @sqlt= 'select @ErrorCount+COUNT(*) FROM V_OA_FromValueInfo WHERE FromNo='+@FromNo+' and '+@strSql;
exec sp_executesql @sqlt ,@params=N'@ErrorCount as int ',@ErrorCount=@ErrorCount
IF @@ERROR > 0
BEGIN
SET @ErrorCount = -1;
RETURN
END
END