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 2000 Forums
 Transact-SQL (2000)
 What if the date field is blank ?

Author  Topic 

Pinto
Aged Yak Warrior

590 Posts

Posted - 2005-06-08 : 05:28:29
If my user leaves the date field blank but fills in another search box, how can I select the call with say surname 'Wood' and any date.

TIA

mr_mist
Grunnio

1870 Posts

Posted - 2005-06-08 : 05:49:56
This means practically nothing unless someone has already read through

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50840

But essentially you would need to assign a default value to your data parameter, and if the value is the default then just select all the dates. (Something like WHERE date = @date or @date = defaultvalue)

-------
Moo. :)
Go to Top of Page

jhermiz

3564 Posts

Posted - 2005-06-08 : 08:25:31
If you need any date then assign null as the default value to your sproc parameter than try this...

SELECT ... FROM YourTable WHERE
((DATEADD(d, DATEDIFF(d, 0, YourDateField), 0) = @DateParam OR @DateParam IS NULL)


Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Imperfection living for perfection --
[url]http://jhermiz.blogspot.com/[/url]
Go to Top of Page

vivek.kumargupta
Starting Member

45 Posts

Posted - 2005-06-10 : 03:27:20
See ISNULL in BOL

Thanks,
Vivek
Go to Top of Page
   

- Advertisement -