存储过程多次插入错误

时间:2016-11-10 01:39:39

标签: sql-server stored-procedures

我在SQL Server 2016中编写了一个简单的存储过程但是当我有2个插入语句时,我不断收到错误消息

  

' End'

附近的语法不正确

我的语法有问题还是不可能?

请注意,它是一个表值参数,我将其作为参数发送到存储过程

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

1 个答案:

答案 0 :(得分:1)

这是您的第一个df = pd.read_table("DataframeString.txt", sep="\s+", header=None, skiprows=3, index_col=0) data = [] with open("DataframeToString.txt", 'r') as f: data.append(f.read().split()) df.index.name = data[0][3] df.columns = data[0][0:3] print(df) # Ion TheoWavelength Blended_Set # Line_Label # H1_4340A Hgamma_5_2 4340.471 None # He1_4472A HeI_4471 4471.479 None # He2_4686A HeII_4686 4685.710 None # vAr4_4711A [ArIV] 4711.000 None # Ar4_4740A [ArIV] 4740.000 None # H1_4861A Hbeta_4_2 4862.683 None

>>> np.load(io.BytesIO(open('zomg.npy', 'rb').read()))
array([1, 2, 3])

接下来的内容是insertInsert Into tbl1Recipients(strEmailSendIDx, strEmailAddress, strDisplayName, strRecipientType) Select * From @Rec 。下一个标记是VALUES,这是没有意义的。

您需要包含要插入的数据。