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

Save

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
    as
    select * from customer

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

    create view newView
    as
    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

References

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

Comments

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...

  • Creating a View in SQL Server

    Use the Management Studio feature of Microsoft SQL Server to learn how to select a database view. Use the Management Studio in...

Related Searches

Check It Out

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

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