0
我写在SQL Server 2016年简单的存储过程,但是当我有2条插入语句我不断收到写着附近的“终结”存储过程多个插入错误
不正确的语法错误
我的语法有问题吗?或者这是不可能的?
请注意,这是我发送到存储过程的参数
SQL语句表值参数:
-- This is the stored procedure CREATE PROCEDURE [dbo].[SampleProcedure] (-- which accepts 2 table value parameters -- It should be noted that the parameter is readonly @Sample As [dbo].[SampleDataType] Readonly, @Rec As [dbo].[SampleRecType] ReadOnly ) AS BEGIN -- We simply insert values into the DB table from the parameter -- The table value parameter can be used like a table with only read rights -- INSERT INTO SampleTable(SampleString, SampleDate) -- SELECT SampleString, SampleDate -- FROM @Sample INSERT INTO tbl1Recipients(strEmailSendIDx, strEmailAddress, strDisplayName, strRecipientType) INSERT INTO tbl1SentEmails(strEmailSendID, dtmSent, strSubject, strBody, strConversationID, strConversationTopic, strConversationIndex, dtmReplied, dtmOpened, dtmClicked, blnTrackOpens, blnTrackClicks, blnTrackReplies, lngMergeID, blnHide, lngLatestEventID, strClickResponse, dtmClickResponse) SELECT * FROM @Sample END
编辑,阅读的意见和建议的答复这是后解决问题:
-- This is the stored procedure CREATE PROCEDURE [dbo].[SampleProcedure] ( -- which accepts one table value parameter. -- It should be noted that the parameter is readonly @Sample As [dbo].[SampleDataType] Readonly, @Rec As [dbo].[SampleRecType] ReadOnly ) AS BEGIN -- We simply insert values into the DB table from the parameter -- The table value parameter can be used like a table with only read rights INSERT INTO tbl1Recipients(strEmailSendID, strEmailAddress, strDisplayName, strRecipientType) SELECT * FROM @Rec INSERT INTO tbl1SentEmails(strEmailSendID, dtmSent, strSubject, strBody, strConversationID, strConversationTopic, strConversationIndex, dtmReplied, dtmOpened, dtmClicked, blnTrackOpens, blnTrackClicks, blnTrackReplies, lngMergeID, blnHide, lngLatestEventID, strClickResponse, dtmClickResponse) SELECT * FROM @Sample END
它所需要的是另一种
SELECT
后,我将数据录入tbl1Recipients
总之,你的语法是错误的。请检查您的INSERT语句的语法 – Squirrel
@Squirrel如果我删除'Insert' for'tbl1Recipients'它的工作。我知道多个插入是允许的......但是我检查了'tbl1Recipients'的值,它似乎没问题。 –
你的插入语句看起来不对。来自'@sample'的select *的结果不能同时适用于具有4列的表格和具有18列的另一个表格。您应该能够使用两个不同的选择结果集来分隔两个插入语句,可能会构建'@samplerecipients和'@sampleemails – BasicIsaac