Dennis Bottjer | ASP.NET + SharePoint Architect, Trainer & Speaker

"An Ounce of Prevention is Worth a Pound of Cure" - Ben Franklin
posts - 168, comments - 59, trackbacks - 41

My Links

News

Add to Technorati Favorites The views expressed in this blog are mine and mine alone, not that of my employer, Microsoft, or anyone else’s. No warrantee is given for the quality of any material on this site.

Tag Cloud

Archives

Post Categories

SQL Query By Year

Say you want to query a table returning all the records from a certain year.  An easy way to do this is to use SQL’s Year Function as follows:

 

Select * From <Table> Where Year(<DateTimeField>) = 2006

Print | posted on Saturday, December 10, 2005 1:12 AM | Filed Under [ SQL & LINQ ]

Feedback

Gravatar

# re: SQL Query By Year

if you have an index on that field, believe it or not it's slightly better to use something like:

select * from table where datetimefield between '1/1/2006 00:00:00' and '12/31/2006 11:59:59'

i believe it has to do with using a function in your where clause which is typically bad juju. in fact, the between will get converted to a >= and <= comparison by sql probably.
1/19/2007 6:11 AM | royashbrook
Comments have been closed on this topic.

Powered by: