This is continuity of my first question in which I wanted to store multiple values in SQL Server variable.I need to loop through @tranId variable which holds two values and then delete a transaction based on the ids I have in @tranId.
This is how my query looks like.
ALTER PROCEDURE "ESG"."SP_ADD_TEST_DATA"
AS
BEGIN
DECLARE @envelopeId table(identifiers VARCHAR(1000));
INSERT INTO @envelopeId (identifiers) VALUES('axaa1aaa-aaaa-a5aa-aaaa-aa8aaaa9aaaa');
INSERT INTO @envelopeId (identifiers) VALUES('bxbb1bbb-bbbb-b5bb-bbb4-bb8bbbb9bbbf');
DECLARE @tranId table(ids INT);
INSERT INTO @tranId SELECT DOCUMENT_SET_TRANSACTION_ID FROM ESG.DOCUMENT_SET_TRANSACTION WHERE IDENTIFIER IN (SELECT identifiers FROM @envelopeId);
BEGIN
DECLARE @transactionId int;
DECLARE @tranId_cursor CURSOR;
SET @tranId_cursor = CURSOR FOR
SELECT * FROM @tranId;
OPEN @tranId_cursor
FETCH NEXT FROM @tranId_cursor INTO @transactionId;
WHILE @@FETCH_STATUS = 0
BEGIN
DELETE FROM ESG.DOCUMENT_SET_TRANS_MDATA WHERE DOCUMENT_SET_TRANSACTION_ID = @transactionId;
END
END
CLOSE @tranId_cursor;
DEALLOCATE @tranId_cursor;
END
This is getting complex and I am not sure how to achieve this gracefully.
Thanks