Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 show results even when parameter is passed as null

Author  Topic 

shantanu88d
Starting Member

35 Posts

Posted - 2011-05-13 : 03:53:55
Hi,
I have a table with entry_date column.
Now I want a query that will take entry_date as parameter. But if entry_date is passed as null, the query will still show all the records. How to achieve this ?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-05-13 : 04:05:12
[code]
where @entry_date is null
or entry_date = @entry_date
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

shantanu88d
Starting Member

35 Posts

Posted - 2011-05-13 : 04:57:08
Hey, awesome, thanks for the soultion

There are no failures...only experiences!
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2011-05-13 : 07:08:15
howzabout...
where entry_date = COALESCE(@entry_date,entry_date)


Yes, i am going for the bad/confusing code. Practicing to be a consultant!

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -