How to add Two different Condition [Resolved]

Posted by Jayakumars under Sql Server on 11/18/2016 | Points: 10 | Views : 1615 | Status : [Member] [MVP] | Replies : 2
Hi

I my Sql Query I need two different where condition concatenations need



for ex:

I pass Stored procedure patameter=1
means i need where empid=1

I pass Stored procedure patameter=2
means i need where empdid=2

but empdid and empdid different table how it possble.

in a single query how to set where statment

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com



Responses

Posted by: Rajnilari2015 on: 11/20/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Try this

Declare @t1 Table(Empid Int)
Declare @t2 Table(Empdid Int)

Insert Into @t1 Select 1 Union All Select 2
Insert Into @t2 Select 1 Union All Select 2

Declare @var1 Int =1
Declare @var2 Int = Null


Select *
From @t1 Where Empid = @var1

Union All

Select *
From @t2 Where Empdid = @var2


--
Thanks & Regards,
RNA Team

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Manicse on: 11/21/2016 [Member] Bronze | Points: 25

Up
0
Down
In Stored procedure itself you can keep a parameter like Status.
If status =1 first condition else second one.

Create PROC PROCNAME(your Parameter,@Status)

{
If(@Status == 1)
{
//FirstQuery
}
Else
{
//Second Query
}

}


Mani.R

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response