Guruji Point - Code You Want To Write

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

Sunday, 15 January 2017

If Else With SQL Server

 No comments   

Introduction

In this article i will explain about how to perform looping in Sql server database with If else Condition.

Practice


In daily practice you are facing these type of condition and you also solve these using your c# code. But Here i will explaining how to do the same task from database level. you don't need to write code in your c# instead of all the condition maintain from procedure level.

In my before last article i explained about Case statement . Same condition i will perform with if else.



Declare @Gender varchar(50);

SET @Gender = (SELECT TOP 1 GenderType FROM PhysicalDesc
                            WHERE ID = 101) 
        IF @Gende = 'M'
          BEGIN
              SET @Gender = 'Male' 
          END
     Else 
              SET @Gender ='Female' 

Print @Gender

In result window of SQL Gender print base on GenderType . 

 IF @Gender = 'M' OR @Gender ='1'
THEN
  RETURN   'Male' 
ELSE
  RETURN 'Female' '
END
Here OR operator same as || in C#. And for && operation in sql we use AND keyword just like OR.
  • 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