SQL在存储过程中插入时导致错误“'=''附近的语法不正确”

时间:2018-05-11 01:07:11

标签: sql sql-server stored-procedures

存储过程代码(我只是剪切了其他代码)

ALTER PROCEDURE [dbo].[SP_v2]
    @CashCountBatchNo INT,
    @CashierID VARCHAR(10),
    @Remarks   VARCHAR(50),
    @CashCount NVARCHAR(1000),
    @ADJ       NVARCHAR(1000) = '',
    @CutOff    VARCHAR(8) = ''
AS
    SET NOCOUNT ON

    DECLARE @tbl TABLE(DENOMINATION MONEY, [COUNT] INT)                
    DECLARE @tblADJ TABLE(Description VARCHAR(300), Amount MONEY)                
    DECLARE @Totals TABLE(CC MONEY, CH MONEY, CASHTOCOLLECT MONEY)

    SET @CashCount = REPLACE(@CashCount, '_S_', ' Select ')                
    SET @CashCount = REPLACE(@CashCount, '_;', ' union all ')                
    SET @CashCount = SUBSTRING(@CashCount, 0, LEN(@CashCount) - 8) 

    INSERT INTO @tbl(DENOMINATION, [COUNT])
         EXEC sp_executesql @CashCount

    SELECT * FROM @tbl
    RETURN

它刚刚成功创建,现在我的问题......

UERMHIMS..Usp_Cashier_SaveCashCount_v2 
'',
'',
'',
'DENOMINATION=1000, COUNT=1 union select DENOMINATION=500, COUNT=1',
'',
''

此时存储过程需要4个参数,当我执行存储过程时,会抛出错误

  

Msg 102,Level 15,State 1,Line 1
  '='附近的语法不正确。

1 个答案:

答案 0 :(得分:1)

您需要在执行语句之前打印出变量{ "$id": "1", "Parent": null, "Name": "TONY", "Children": { "$id": "2", "$values": [ { "$id": "3", "Parent": { "$ref": "1" }, "Name": "ESTHER", "Children": { "$id": "4", "$values": [] } } ] } }

从我能说出的逻辑来看,@CashCount的内容将类似于:

@CashCount

这不是有效的SQL。

作为测试,我在SQL Fiddle中运行此SQL,并得到完全相同的错误。