I have a very strange situation with which I hope you can provide some insight. I have the following script that I use to activate certain features on our clients' databases:
DECLARE @MiscChargeName varchar (80),
@MiscChargeCode int,
@MiscChargeDetailName varchar(80),
@MiscChargeDetailCode int,
@DisplayOrder int
SELECT @MiscChargeCode = 20410,
@MiscChargeDetailCode = @MiscChargeCode-1
SELECT @MiscChargeName = Description FROM VMTransactionCode WHERE Code = @MiscChargeCode
SELECT @MiscChargeDetailName = Description FROM VMTransactionCode WHERE Code = @MiscChargeDetailCode
IF NOT EXISTS (SELECT * FROM VMTransactionCodeClient WHERE Code = @MiscChargeCode)
INSERT INTO VMTransactionCodeClient (Code)
VALUES (@MiscChargeCode)
IF NOT EXISTS (SELECT * FROM VMTransactionCodeClient WHERE Code = @MiscChargeDetailCode)
INSERT INTO VMTransactionCodeClient (Code)
VALUES (@MiscChargeDetailCode)
UPDATE VMIFAccountTranslationOut
SET PostPnLRoutine = 1
WHERE AccountCode = @MiscChargeDetailCode
AND ChargeType is NOT NULL
BEGIN TRANSACTION
DECLARE @VoyageID int,
@ID int,
@Dept int,
@Company int
DECLARE VoyageCursor CURSOR LOCAL FAST_FORWARD
FOR SELECT ID, Dept, Company FROM VMVoyage WHERE Status NOT IN ('Finalised Copy', 'Cancelled')
OPEN VoyageCursor
FETCH NEXT FROM VoyageCursor INTO @VoyageID, @Dept, @Company
WHILE (@@FETCH_STATUS = 0)
BEGIN
IF NOT EXISTS (SELECT ID FROM PLAccount WHERE VMVoyage = @VoyageID AND TransactionCode = @MiscChargeCode)
BEGIN
EXECUTE ssl_GetPLAccountCallSeq 1, @ID OUTPUT
INSERT INTO PLAccount (ID, Dept, VMVoyage, TransactionCode, GroupDescription, GroupReference, Budget, Actual, Receipt, DetailReference, Company, AccountState)
VALUES (@ID, @Dept, @VoyageID, @MiscChargeCode, 'System', NULL, NULL, NULL, NULL, NULL, @Company, NULL)
END
IF NOT EXISTS (SELECT * FROM VMVoyageMiscExp WHERE Voyage = @VoyageID AND Type = @MiscChargeCode)
BEGIN
EXECUTE ssl_GetVMVoyageMiscExpCallSeq 1, @ID OUTPUT
INSERT INTO VMVoyageMiscExp (ID, Voyage, Type, Expense, ExpCurr, Due, Status, DAStatus)
VALUES (@ID, @VoyageID, @MiscChargeCode, NULL, NULL, NULL, 'B', NULL)
END
FETCH NEXT FROM VoyageCursor INTO @VoyageID, @Dept, @Company
END
CLOSE VoyageCursor
DEALLOCATE VoyageCursor
COMMIT TRANSACTION
GO
I have opened the script as is in a new window and pressed F5 to execute. The script ran through fine and I have informed the client that all in order. However later we found that there was a block on their database and after extensive investigation, I have found that the COMMIT TRANSACTION did not actually commit. In the same window, I had to highlight the COMMIT TRAN seperately and again execute to commit the script to the transaction. I have not had this on any other client's database or on my local databases. If I execute the whole script, the COMMIT TRANSACTION is included in the execution. Since this is in their PROD environment, I can't really do any further tests, but all my local tests have proved to have the expected result and I cannot explain to the client why this has happened only on their side. I have searched for any possible setting/configuration that could result in this, but have not found anything. I will be forever greatful if you can provide some insight on this mystery!
Thank you in advance.