Reputation: 11
I'm using If Condition Srore procedure...
But .. I need if stored procedure with where in if else condition and concatenate with to and condition in Query..
Examble
create procedure [dbo].[Sp_Name]
@code int,
@dCode int
As
select <.........> from <tablename>
Where empcode=@code
if (@dCode != 0)
Begin
And dptcode=@ dCode
End
Please help me find a solution...
Upvotes: 0
Views: 196
Reputation: 2500
create procedure [dbo].[Sp_Name]
@code int,
@dCode int
As
select <.........> from <tablename>
Where empcode=@code
if (@dCode != 0)
Begin
Select dptcode=@dCode
End
Not sure if that's what the poster was after, can some one please edit the text and correct it.
Upvotes: 0
Reputation: 56697
Would this work for you:
create procedure [dbo].[Sp_Name]
@code int,
@dCode int
As
select <.........> from <tablename>
Where empcode=@code AND (@dCode = 0 OR dptcode=@dCode)
Your question is pretty hard to understand - this is what I guess from what I actually did understand.
Upvotes: 1