SQL Server中仅年份的DateTime查询 [英] DateTime query on only year in SQL Server

查看:219
本文介绍了SQL Server中仅年份的DateTime查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据匹配的年份选择多个记录,例如在表选项卡
中,其中列为 [id] int [name] varchar [bookyear] datetime

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

我想选择所有年份为2009年的记录。

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

以下查询给出0个结果:

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


推荐答案

select id,name,bookyear from tab1 where year(bookyear) = 2009

这篇关于SQL Server中仅年份的DateTime查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆