Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have a column session_date that holds the date in the format: m/d/yyyy or m/dd/yyyyhow do I write my select statement to grab all records by a specific year?SELECT *FROM mytableWHERE session_date = Thanks for any help.
-Dman100-
Posting Yak Master
210 Posts
Posted - 2007-01-24 : 11:52:36
Disregard...I got it.Thanks.
spirit1
Cybernetic Yak Master
11752 Posts
Posted - 2007-01-24 : 11:53:40
WHERE year(session_date) = 2006won't use an index on session_datethis will:
DECLARE @year CHAR(4), @dateFrom DATETIME, @dateTo DATETIMEselect @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