Last active
September 16, 2017 03:06
-
-
Save ghulamostafa/62e060f87ceb95edb99a870c70027226 to your computer and use it in GitHub Desktop.
This is a sample for select and insert stored procedures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ============================================= | |
-- Author: Ghulam Mustafa | |
-- Create date: 30-Jun-2017 | |
-- Description: Here goes the description for Select Stored Procedure | |
-- ============================================= | |
CREATE PROCEDURE SP_NameOfStoredProcedureForSelect | |
-- Add the parameters for the stored procedure here | |
@Action varchar(50) = NULL | |
/*Here goes the rest of the parameters*/ | |
,@result int = 0 output | |
,@message nvarchar(150) = NULL output | |
AS | |
BEGIN | |
-- SET NOCOUNT ON added to prevent extra result sets from | |
-- interfering with SELECT statements. | |
SET NOCOUNT ON; | |
SELECT FirstName, LastName | |
FROM PersonTable | |
SET @result = 1 | |
SET @message = 'Message back to front end' | |
END | |
-- ============================================= | |
-- Author: Ghulam Mustafa | |
-- Create date: 30-Jun-2017 | |
-- Description: Here goes the description for Insert/Update Stored Procedure | |
-- ============================================= | |
CREATE PROCEDURE SP_NameOfStoredProcedureForInsert | |
-- Add the parameters for the stored procedure here | |
@Action varchar(50) = NULL | |
/*Here goes the rest of the parameters*/ | |
,@result int = 0 output | |
,@message nvarchar(150) = NULL output | |
AS | |
BEGIN | |
-- SET NOCOUNT ON added to prevent extra result sets from | |
-- interfering with SELECT statements. | |
SET NOCOUNT ON; | |
BEGIN TRY | |
BEGIN TRANSACTION | |
INSERT INTO | |
PERSONTABLE | |
(FirstName, LastName) | |
VALUES | |
('Ghulam', 'Mustafa') | |
SET @result = 1 | |
SET @message = 'Message back to front end' | |
COMMIT TRANSACTION | |
END TRY | |
BEGIN CATCH | |
IF @@TRANCOUNT > 0 | |
BEGIN | |
ROLLBACK TRANSACTION | |
END | |
SET @result = 0 | |
SET @message = ERROR_MESSAGE() /*This will return the error that caused this exception*/ | |
END CATCH | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment