If else in stored procedure sql server

If else in stored procedure sql server

Hello Everyone,  I am going to share the code sample to use of If else in stored procedure SQL Server.

The query as given below. 
/*
     * IF ELSE IN STORED PROCEDURE SQL SERVER.
     * USER OF NOT-IN  in SQL SERVER.
*/

ALTER PROCEDURE [dbo].[SP_VALIDATE_ACCOUNT]
(
   @ACCOUNTID VARCHAR(40) ='ACT9979',
   @STATUS CHAR(1) OUT
)
AS
BEGIN
IF NOT EXISTS (SELECT ACCOUNTID FROM [DBO].[ACCOUNTNUMBER] WHERE ID=@ACCOUNTID)
    BEGIN
           SET @STATUS ='Y'
    END
    BEGIN
           SET @STATUS ='N'
           RETURN @STATUS
    END  

END
ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book