How to Use Today's Date in a SQL View Filter


A SQL Server "view" provides developers with the ability to retrieve common table elements in pre-compiled code. A view is used in the same way a table is queried. The view is already compiled, however, so it improves performance for the desktop or web application. The "GetDate()" function adds the current date to the view. "GetDate()" retrieves the current date on the SQL Server and adds it to the view's parameters. This is available in SQL Server 2005 and 2008.

  • Right-click the view name and select "Modify." In the toolbar, click "SQL View" to view the text-based code for the object.

  • Add the column you want to use as the current date filter. For example, a view retrieves all customers who signed up on the current date retrieved by GetDate(). The following is an example of a SQL view:

    create view newView
    select * from customer

    The above code retrieves all customer records. The following code filters the customers by signup date:

    create view newView
    select * from customer
    where signup = getDate()

  • Press the "F5" key to execute and save your changes. You can test your changes by executing the view in your SQL console. Type the following code into the console and press "F5" to view the new view filters:

    select * from newView

Related Searches


  • Photo Credit valentine"s day calendar image by Wolszczak from
Promoted By Zergnet


You May Also Like

  • How to Select a System Date in Informix

    IBM Informix is a database software program capable of arranging your business needs on a day-to-day basis. Returning the current system date...

  • ANSI SQL Tutorial

    American National Standards Institute (ANSI) provides common standards for computer programming languages such as Structured Query Language (SQL). SQL has four standard...

  • How to Determine if a View Exists in SQL

    Structured Query Language (SQL ) is used for managing data in relational database management systems like Microsoft SQL Server and Oracle. In...

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!