Saturday, July 23, 2011

SQL NOW() Function


The NOW() Function

The NOW() function returns the current system date and time.

SQL NOW() Syntax

SELECT NOW() FROM table_name


SQL NOW() Example

We have the following "Products" table:
Prod_IdProductNameUnitUnitPrice
1Jarlsberg1000 g10.45
2Mascarpone1000 g32.56
3Gorgonzola1000 g15.67
Now we want to display the products and prices per today's date.
We use the following SELECT statement:
SELECT ProductName, UnitPrice, Now() as PerDate FROM Products
The result-set will look like this:
ProductNameUnitPricePerDate
Jarlsberg10.4510/7/2008 11:25:02 AM
Mascarpone32.5610/7/2008 11:25:02 AM
Gorgonzola15.6710/7/2008 11:25:02 AM

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Deep's | Bloggerized by Deep - Deep's Templates | ElearSQL-Server