0

How to check parameter has null or not in stored procedure

e.g

select * from tb_name where name=@name

i need to check if @name has values or null means.how to do it.thanks...

1
  • You can do something like select * from tb_name where @name IS NULL OR name=@name Commented Dec 26, 2013 at 16:57

3 Answers 3

2

Is this what you want?

select * from tb_name where name=@name and @name is not null

Actually, the extra check is unnecessary, because NULL will fail any comparison. Sometimes, NULL is used to mean "get all of them". In that case, you want:

select * from tb_name where name=@name or @name is null
Sign up to request clarification or add additional context in comments.

Comments

1

In case you want results where Name is not null and equal to @name Try:

select * from tb_name where name=@name AND @name IS NOT NULL

If you want results where Name is null Or equal to @name Try:

select * from tb_name where name=@name OR @name IS NULL

Where you looking for one of those?

Comments

1
select * 
from tb_name 
where ((@name  is null) or ([name] = @name))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.