Guruji Point - Code You Want To Write

  • Home
  • Asp.Net
  • WCF
  • SQL
  • Type Script
  • AngularJS
  • Tech News
  • Blog
  • Earn Online

Sunday, 20 November 2016

Pass Output Parameter using Stored Procedure in SQL Server

 No comments   


Introduction

In this article i will explain about How to pass a output parameter in Stored Procedure and return that out parameter value in your application.

Practice

Here i am writing my Stored Procedure to return the output or something as Text using out parameter.

CREATE PROCEDURE usp_EmployeeInfo
@EmpName varchar(50),
@Password varchar(50),
@FirstName varchar(50),
@LastName varchar(50),
@Email varchar(50),
@PhoneNo varchar(50),
@Location varchar(50),
@Created_By varchar(50),
@ERROR VARCHAR(100) OUT

AS

BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from  interfering with SELECT  
-- statements.
               
SET NOCOUNT ON;



--Checking Condition if Employee exists or not , Return different message in both cases if exist or not.

IF NOT EXISTS(SELECT * FROM User_Information WHERE EmpName=@EmpName)
BEGIN
INSERT INTO EmployeeInfo
(
EmpName,
[Password],
FirstName,
LastName,
Email,
PhoneNo,
Location,
Created_By
)
VALUES
(
@EmpName,
@Password,
@FirstName,
@LastName,
@Email,
@PhoneNo,
@Location,
@Created_By
)
--If Employee Successfully Registerd returing this Message as Output Parameter
SET @ERROR=@EmpName+' Registered Successfully'
END
ELSE
BEGIN
--If Employee already Exists  returning this Message as Output Parameter
SET @ERROR=@EmpName+ ' Already Exists'
END
END

Here you can see i  used @ERROR as out parameter and based on this value we can display this message in our application while we call this Procedure.


  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Facebook Updates

Guruji Point

Categories

Comman table Expression in SQL Dynamic Grid Row IQueryable in c# Learn AngularJS Scope_Identity() Use of indexes comma seperated string in sql row_number() and dense_rank() salary table structure. while loop in sql why do we need cursor why tuple used

About Us

This blog is about the Programming ,Tech News and some intresting facts related Contents. Here you can find fundamental and expert level topic of programming languages very practically related to C# , Asp.Net ,Sql-Server, JavaScript, Jquery, WebServices And also Web-Api, WCF ,WPF, Angular Js.

Contact Us

Email Us - gurujipoints@gmail.com
Contact- 8077657477

Reach Us

Copyright © Guruji Point - Code You Want To Write