SQL Server: How to handle two different cases in Where clause -



SQL Server: How to handle two different cases in Where clause -

i have stored procedure in sql server 2008 used fetch info table.

my input parameters are:

@category nvarchar(50) = '', @departmentid int

my clause is:

where a.departmentid = @departmentid , a.category = @category

is there way can apply case statement (or similar) clause should check category match if @category not '' , otherwise select categories ?

the thing think of here utilize following. technically works can't check exact category matches required here:

where a.departmentid = @departmentid , a.category '%'+@category+'%'

many help this, tim.

you can modify where clause follow:

where a.departmentid = @departmentid , (@category = '' or a.category = @category)

sql sql-server case where where-clause

Comments

Popular posts from this blog

php - How to pass multiple values from url -

database - php search bar when I press submit with nothing in the search bar it shows all the data -

ios - How to load .png images from Documents folder of an app -