SQL Server : check if variable is Empty or NULL for WHERE clause

Just use

If @searchType is null means ‘return the whole table’ then use

WHERE p.[Type] = @SearchType OR @SearchType is NULL

If @searchType is an empty string means ‘return the whole table’ then use

WHERE p.[Type] = @SearchType OR @SearchType=""

If @searchType is null or an empty string means ‘return the whole table’ then use

WHERE p.[Type] = @SearchType OR Coalesce(@SearchType,'') = ''

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)