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
 General SQL Server Forums
 New to SQL Server Programming
 Filter by date

Author  Topic 

Slason
Starting Member

3 Posts

Posted - 2011-11-02 : 05:44:04
Hello,

I am working on a school project, and I am making a website which observes weather. I am saving each "observation" in my database. I am listing all observations up on a page, and I want the user to have the ability to filter them by date.

I am thinking of having a textfield up, which filters all observations by date. I am currently using this code:
SELECT *
FROM observations
WHERE (date BETWEEN '' AND '')


How do I modify the code that I can use a form on the webpage, that specifies what should stand between the ' ' ?

Any help would be appreciated .

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-02 : 05:47:23
make two date parameters @StartDate and @EndDate of type date
and use like

SELECT *
FROM observations
WHERE (date BETWEEN @StartDate AND @EndDate )

in case you want to consider time also then make datatype datetime and use like


SELECT *
FROM observations
WHERE (date >=@StartDate AND date < @EndDate+1 )




------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-11-03 : 06:18:48
You can refer various examples here
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/21/understanding-datetime-column-part-iii.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -