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
 SQL SERVER CURRENT DATE

Author  Topic 

Amber_Deslaurier
Starting Member

40 Posts

Posted - 2010-06-26 : 20:30:01
Hi,

I would like my query to have a where clause that would restrict output to the current Year (2010) and Current Month (6) and current day (26)

what is the correct syntax?

***([My fields] are in brackets)***


where [Date] = currentYear and [Month] = currentMonth and [Day] = currentDay ???

TY

Amber.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-06-26 : 20:50:35
Can you change your database design so that the information is stored in one column that uses a datetime data type? Separating them like that isn't typically done in OLTP systems.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Amber_Deslaurier
Starting Member

40 Posts

Posted - 2010-06-26 : 21:05:07
yes Tara I would but since its a view that is developed by another organization I have no way of challanging their architecture... I do need to extract their data but I need to ensure I extract based on the criteria identified... is their keywords for Current Year and current month that I can use successfully? Thanks.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-06-27 : 00:40:59
You can use YEAR(), MONTH(), and DAY() functions along with GETDATE(). GETDATE() provides the current date and time, so you'll need to extract the parts you need. You can also use the CONVERT function with the appropriate style or DATEADD function. Search these forums for examples with GETDATE().

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -