Introduction
In this article i will explain about how to perform looping in Sql server database with If else Condition.
BEGIN
In result window of SQL Gender print base on GenderType .
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'
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.
0 comments:
Post a Comment