尝试在下面运行我的动态 sql 时,我目前收到以下错误;有什么我遗漏的东西导致这个错误被抛出吗?......
消息 102,级别 15,状态 1,过程计算,第 32 行 ')' 附近的语法不正确。
CREATE PROCEDURE calc(@pC INT, @Array1 varchar(500) ,@pT VARCHAR(15), @pTN VARCHAR(15), @pPK BIGINT, @pCI FLOAT, @pFK BIGINT)
AS
BEGIN
--calculate peer statistics for level of peer group
DECLARE @sMI FLOAT, @num25 FLOAT, @num75 FLOAT, @num25V FLOAT, @num75V FLOAT
DECLARE @sMD FLOAT, @sME FLOAT, @sIQ FLOAT, @sSD FLOAT, @sMin FLOAT, @sMax FLOAT, @sDiff FLOAT
DECLARE @sLK BIGINT, @sNL BIGINT, @sNI BIGINT
DECLARE @sUNC NVARCHAR(5)
DECLARE @SQL NVARCHAR(MAX)
SET @SQL = 'IF ('+@pFK+' = 0)
BEGIN
INSERT INTO '+@pTN+' (fldBA) VALUES (2);
END
ELSE
BEGIN
IF ((SELECT COUNT(*) FROM '+@pTN+' WHERE fldFPK = '+@pFK+' and fldPK='+@pPK+' and fldCIA='+@pCI+') > 0)
BEGIN
UPDATE '+@pTN+' SET fldAVA = 0, fldPK = '+@pPK+', fldDTA = GETDATE(), fldCIA = '+@pCI+',
fldME = '+@sME+',fldMD = '+@sMD+',fldIQ = '+@sIQ+',fldSD = '+@sSD+', fldND = '+@pC+' + 1,
fldNI = '+@sNI+', fldNL = '+@sNL+', fldMin = '+@sMin+', fldMax = '+@sMax+',fldUNC = '+@sUNC+'
WHERE fldFPK = '+@pFK+' and fldPK = '+@pPK+' and fldCIAc = '+@pCI+'
END
ELSE
BEGIN
INSERT INTO '+@pTN+' (fldFPK, fldAVA, fldPK, fldDTA, fldCIA,fldMean,fldMD,fldIQ,fldSD,fldND,fldNI,fldNL,fldMin,fldMax,fldUNC) VALUES('+@pFK+', 0, '+@pPK+', GETDATE(),
'+@pCI+', '+@sME+', '+@sMD+','+@sIQ+','+@sSD+','+@pC+'+ 1, '+@sNI+', '+@sNL+', '+@sMin+', '+@sMax+', '+@sUNC+')
END
END'
exec @SQL