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
 getting all records by specific year

Author  Topic 

-Dman100-
Posting Yak Master

210 Posts

Posted - 2007-01-24 : 11:41:18
I have a column session_date that holds the date in the format: m/d/yyyy or m/dd/yyyy

how do I write my select statement to grab all records by a specific year?

SELECT *
FROM mytable
WHERE session_date =

Thanks for any help.

-Dman100-
Posting Yak Master

210 Posts

Posted - 2007-01-24 : 11:52:36
Disregard...I got it.
Thanks.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-01-24 : 11:53:40
WHERE year(session_date) = 2006
won't use an index on session_date

this will:

DECLARE @year CHAR(4), @dateFrom DATETIME, @dateTo DATETIME
select @year = '2006'
select @dateFrom = @year + '0101',
@dateTo = DATEADD(yy, 1, @dateFrom)

SELECT * FROM mytable WHERE session_date BETWEEN @dateFrom AND @dateTo





Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page
   

- Advertisement -