I'm trying to write the following stored procedure, but SQL has issues with the If statement. How do I include an case/if/etc into the where clause?
CREATE procedure [dbo].[MyProcedure]
@blnCheckbox bit = 1
As
Select Field1,
Field2,
Field3
From MyTable
Where Field1 like '%blah%'
and Field2 like '%blahblah%'
If @blnCheckbox = 0
Begin
and Field3 like '%blah%'
End
CREATE procedure [dbo].[MyProcedure]
@blnCheckbox bit = 1
As
Select Field1,
Field2,
Field3
From MyTable
Where Field1 like '%blah%'
and Field2 like '%blahblah%'
If @blnCheckbox = 0
Begin
and Field3 like '%blah%'
End