我的存储过程:
DECLARE @KSTime DATETIME,@JSTime DATETIME,@TableShu INT,@UPDID VARCHAR(40),@TempShu INT,@TempZhi numeric(18, 3),@sql VARCHAR(1000),@BZhiBiao numeric(18, 3),@BuMenName VARCHAR(40)
SET @KSTime=@TreeID+'-1'
SET @JSTime=DATEADD(M,1,@KSTime)
SET @BuMenName=(SELECT MingCheng FROM SC_BuMen WHERE DID=@BuMenID)
--首先获取指标数据
INSERT @FanHui (DID,XuHao,GLXiang,ISBianJi) SELECT 'M'+CAST(XuHao AS VARCHAR(2)),XuHao,GLXiang+FenZhi,CASE WHEN XuHao=5 THEN 0 ELSE 1 END FROM BD_GuanLiJiHua WHERE ShanChu!='1' AND NianFen=DATEPART(YEAR,@KSTime) ORDER BY XuHao
--获取上月指标数据
IF (SELECT COUNT(DID) FROM KH_MonthBao WHERE ShanChu!='1' AND ZhuangTai='1' AND BuMenID=@BuMenID AND CAST(CAST(NianFen AS VARCHAR(4))+'-'+CAST(YueFen AS VARCHAR(2))+'-1' AS DATETIME)=DATEADD(M,-1,@KSTime))>0
BEGIN
SET @TableShu=(SELECT COUNT(DID) FROM @FanHui)
SET @TempShu=1
SET @UPDID=(SELECT DID FROM KH_MonthBao WHERE ShanChu!='1' AND ZhuangTai='1' AND BuMenID=@BuMenID AND CAST(CAST(NianFen AS VARCHAR(4))+'-'+CAST(YueFen AS VARCHAR(2))+'-1' AS DATETIME)=DATEADD(M,-1,@KSTime))
WHILE @TempShu<=@TableShu
BEGIN
SET @sql='SELECT @TempZhi=M'+CAST(@TempShu AS VARCHAR(2))+' FROM KH_Item WHERE ShanChu!=1 AND UPDID='''+@UPDID+''''
EXEC sp_executesql @TempZhi,N'@TempZhi int OUTPUT',@sql OUTPUT
UPDATE @FanHui SET SZhiBiao=@TempZhi WHERE DID='M'+CAST(@TempShu AS VARCHAR(2))
SET @TempShu=@TempShu+1
END
END
错误:消息 214,级别 16,状态 2,过程 sp_executesql,第 1 行 过程需要类型为 'ntext/nchar/nvarchar' 的参数 '@statement'。
请问各位大神这是哪里有问题
@sql VARCHAR(1000) 变更为 @sql NVARCHAR(1000) 或者更大 @sql NVARCHAR(max)