我正在尝试从表中删除某些条目时,我的SP会抛出错误。为了安全起见,我得到IF EXISTS
并在其下面我有删除声明,但我收到此错误
Incorrect syntax near the keyword 'DELETE'.
删除stmt
IF EXISTS (DELETE FROM myTable WHERE id IN ((SELECT ids FROM @tranId)));
我不确定语法是否不正确。
答案 0 :(得分:6)
IF
是不必要的,额外的括号也是如此:
DELETE FROM ESG.DOCUMENT_SET_TRANS_MDATA
WHERE DOCUMENT_SET_TRANS_MDATA.DOCUMENT_SET_TRANSACTION_ID IN (SELECT ids FROM @tranId);
DELETE FROM ESG.DOCUMENT_TRANSACTION
WHERE DOCUMENT_TRANSACTION.DOCUMENT_SET_TRANSACTION_ID IN (SELECT ids FROM @tranId);
DELETE FROM ESG.DOCUMENT_SET_TRANSACTION
WHERE DOCUMENT_SET_TRANSACTION.DOCUMENT_SET_TRANSACTION_ID IN (SELECT ids FROM @tranId);