Select all if parameter is null in stored procedure?

There is no need to do AND (@serie_type IS NULL OR S. Type = @serie_type) as SQL Server has a built in function to do this logic for you Try this: AND S. Type = isnull( @serie_type, S.

Type) This returns true if @serie_type is null or the result of @serie_type = S. Type if @serie_type is not null From the MSDN : IsNull Replaces NULL with the specified replacement value ISNULL ( check_expression , replacement_value ) The value of check_expression is returned if it is not NULL; otherwise, replacement_value is returned after it is implicitly converted to the type of check_expression, if the types are different.

There is no need to do AND (@serie_type IS NULL OR S. Type = @serie_type) as SQL Server has a built in function to do this logic for you. Try this: .. AND S.

Type = isnull( @serie_type, S. Type) This returns true if @serie_type is null or the result of @serie_type = S. Type if @serie_type is not null.

From the MSDN: IsNull Replaces NULL with the specified replacement value. ISNULL ( check_expression , replacement_value ) The value of check_expression is returned if it is not NULL; otherwise, replacement_value is returned after it is implicitly converted to the type of check_expression, if the types are different.

What's wrong with this.... – Preet Sangha Sep 22 at 11:31 1 @jeroenh : looks like you'are wrong, ISNULL ( check_expression , replacement_value ) - "Returns the same type as check_expression. " – sll Sep 22 at 11:35 @jeroenh - I've edit that answer. You're wrong.

I've been using this for years on SQL Server. – Preet Sangha Sep 22 at 11:42 You're absolutely right, learned something new today. Truly sorry – jeroenh Sep 22 at 12:04 @Preet Sangha : what you mean saying "no need to do ..."?

This is not a hack but ANSI SQL construction, unlike ISNULL is T-SQL specific. I'm cqan't understand why "no need to do" sentense, is there any side effects you mean or what? More over, from my point of view condition with OR is much cleaner then ISNULL – sll Sep 22 at 14:10.

The common approach is: WHERE C. Id = @company AND S. Created >= @from AND S.Created.

Try this : SELECT * FROM Company C JOIN Series S ON S. Company_FK = C. Id WHERE C.Id = @company AND S.

Created >= @from AND S. Created Type = ISNULL(@serie_type,S. Type).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions