Wednesday, 18 March 2020

MSSQL - Fix Error - Incorrect syntax near the keyword 'Tran'

Watch this example on YouTube




To fix it replace

ALTER PROCEDURE spTest
    @Name Varchar(10)
AS
BEGIN
    SET NOCOUNT ON;
    BEGIN Tran
        IF @Name is Null
        BEGIN
            Rollback
            Return
        END
        Select * FROM Test1 Where Name = @Name;
    END Tran
   
END
GO

With

ALTER PROCEDURE spTest
    @Name Varchar(10)
AS
BEGIN
    SET NOCOUNT ON;
    BEGIN Tran
        IF @Name is Null
        BEGIN
            Rollback
            Return
        END
        Select * FROM Test1 Where Name = @Name;
    COMMIT Tran
   
END
GO


No comments:

Post a Comment