Hai,
I wrote a conditional query with OR Statement by avoiding If..Else Statement.
Declare @AccountMaster Table
(
AccID Int,
CustID Int,
Name Varchar(50)
)
Insert Into @AccountMaster Values
(1,101,'Chandu'),
(2,102,'Aromal'),
(3,103,'Thacholi'),
(4,104,'Unniyarcha')
Declare @Flag Bit = 0, --// If 0 -> AccID, 1 --> CustID
@Account Int = 2
Select AccID,CustID,Name
From @AccountMaster
Where (@Flag = 1 And CustID = @Account)
OR (@Flag = 0 And AccID = @Account)
Eg.,Normal Query Using If..Else Statement
If @Flag = 1
Begin
Select AccID,CustID,Name
From @AccountMaster
Where CustID = @Account
End
Else
Begin
Select AccID,CustID,Name
From @AccountMaster
Where (AccID = @Account)
End
No comments:
Post a Comment