首页新闻找找看学习计划

消息 214,级别 16,状态 2,过程 sp_executesql,第 1 行 过程需要类型为 'ntext/nchar/nvarchar' 的参数 '@statement'。

0
[已关闭问题] 关闭于 2017-09-15 14:32

 我的存储过程:

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'。

请问各位大神这是哪里有问题

cai先sen是什么的主页 cai先sen是什么 | 初学一级 | 园豆:154
提问于:2017-06-14 16:23
< >
分享
所有回答(1)
0

@sql VARCHAR(1000) 变更为 @sql NVARCHAR(1000) 或者更大 @sql NVARCHAR(max)

zhanfuzhi | 园豆:202 (菜鸟二级) | 2019-08-19 14:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册