Skip to content
Advertisement

DateTime query on only year in SQL Server

I want to select multiple records on the basis of a matching year, for example in table tab where columns are [id] int, [name] varchar, [bookyear] datetime

I want to select all records where the year is 2009.

The following query gives 0 results:

    SELECT [ACCNO]
      ,[Roll No]
      ,[IssueDate]
      ,[DueDate]
  FROM [test1].[dbo].[IssueHis$] 
  where [IssueDate]  between 12-12-2004 and 1-01-2010

Advertisement

Answer

select id,name,bookyear from tab1 where year(bookyear) = 2009
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement