SQLTeam.com | Weblogs | Forums

Two options on Where Clause

Hi There,
Is it possible to have two options on a WHERE clause? Both options below don't work.

Declare @ID VarChar (25)
Set @ID = 'WES78'
Select * From Matters
Where Case @ID When '' Then ID like '%' Else ID like @Ex_ID + '-%' End

Declare @ID VarChar (25)
Set @ID = 'WES78'
Select * Matters
Case @ID When '' Then Where ID like '%' Else Where ID like @ID + '-%' End


Try this:

WHERE (@ID = '' OR ID LIKE @ID + '-%')

1 Like

Thanks al million, it works. Fantastic.

You have made it so simple.