Click here to Skip to main content
16,020,347 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all I have a stored procedure where I have gone for Transaction as per the requirement, this is my SP

SQL
CREATE PROCEDURE ProcName
@Id INT,
@user_id INT
AS
 BEGIN
    BEGIN TRANSACTION [transName]
    BEGIN TRY

        DELETE 
        FROM    table1
        WHERE   UserId= @user_id 

        UPDATE  table2
        SET     DATE_MODIFIED = GETDATE()
        WHERE   ID= @Id

        COMMIT TRANSACTION [transName]

    END TRY
BEGIN CATCH
        ROLLBACK TRANSACTION [transName]
        THROW
END CATCH
END


I am getting an exeception like incorrect syntax near THROW can some tell where I am going wrong
Posted
Updated 13-Oct-14 23:24pm
v2
Comments
Herman<T>.Instance 14-Oct-14 5:40am    
add ; after each line in CATCH block

MSDN documentation is a good place to start and read about how to use THROW (you have to supply error parameters): http://msdn.microsoft.com/en-us/library/ee677615.aspx[^]
 
Share this answer
 
Comments
demouser743 14-Oct-14 5:32am    
But it is not mandatory to pass error parameters for THROW, if I comment this line and execute my SP it is working fine ROLLBACK TRANSACTION [transName]. But if I include that I am getting the exception
 
Share this answer
 
Comments
Herman<T>.Instance 14-Oct-14 5:44am    
the @@TranCount ?
demouser743 14-Oct-14 6:37am    
not only that we need to return the mesaage as varchar

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900