0

Why would I get an 'incorrect syntax' error with this (on the OUTPUT keyword):

DELETE tb
    FROM dbo.TransactionBatch tb
    OUTPUT Deleted.TransactionID INTO #TransactionIDs
    INNER JOIN @BatchTransactionIDs tid 
        ON tb.TransactionID = tid.TransactionID

@BatchTransactionIDs is a User-Defined Table type

2

The OUTPUT has to go before the FROM.

DELETE tb
    OUTPUT Deleted.TransactionID INTO #TransactionIDs
    FROM dbo.TransactionBatch tb
    INNER JOIN @BatchTransactionIDs tid 
        ON tb.TransactionID = tid.TransactionID
0

The OUTPUT clause belongs before the FROM clause.
See https://docs.microsoft.com/en-us/sql/t-sql/statements/delete-transact-sql

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.