请教一个sql语句的写法? 我的数据表里有一列 “修改时间”是:2009-07-12 11:25:122009-06-10 11:25:122008-04-15 12:15:44……现在我想 取出所有年是 2009 年的数据,应该怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select *from tbwhere year(datefield)=2009 select * from tb where year(修改时间)=2009 select *from tbwhere year(修改时间)=2009 本帖最后由 libin_ftsafe 于 2009-07-08 16:11:16 编辑 1.select * from tbl_charge where charindex('2009',recordDate)>02.select * from tb where year(修改时间)=2009 select * from tb where year('日期字段')=2009 select *from tbwhere left(修改时间, 4)=2009 建议楼主用这个 select * from tb where convert(varchar,修改时间,112) like '2009%' 或者是这个: select * from tb where left(convert(varchar,修改时间,112),4)='2009' 本帖最后由 hery2002 于 2009-07-08 19:48:24 编辑 select * from 表 where DATENAME(yy,修改时间)='2009' select * from table where year([time])=2009select * from table where [time]>=2009-1-1 and [time]<2010-1-1 你用的不是mssql么?如果是就记得 这个convert()函数的用法吧,我的例子里已经写清楚了主要这样可以准确的吧日期数据类型转换成为字符型,这样更方便而其他的 写法比如 修改时间>='2009-01-01' 可是可以但是,有的时候会出现一点问题,比如说用between 的时候,可能会没有包含2009-01-01这一天反正我经常都是用convert()转换成字符形的。 select *from tbwhere year(datefield)=2009 如何实现一列有多种情况的问题 求一更新语句--谢谢 while循环遍历一个结果集? 一对多表查询不重复显示怎么写 为什么我这样的查询的不到这个结果呢,请高人帮忙 求tsql: 纵横两向打乱-表的魔方变换 求排在最前(后)的5条记录 游标 问题!十万火急 前辈请指教 子查询返回的值不止一个.如何解决呢?在线等待啊。。急!!! 如何在isql中更换登录用户? 求个函数 非常感谢!求一SQL语句!
from tb
where year(datefield)=2009
from tb
where year(修改时间)=2009
1.select * from tbl_charge where charindex('2009',recordDate)>0
2.select * from tb where year(修改时间)=2009
from tb
where left(修改时间, 4)=2009
select
* from
tb where convert(varchar,修改时间,112) like '2009%' 或者是这个:
select
* from
tb where left(convert(varchar,修改时间,112),4)='2009'
select * from table where [time]>=2009-1-1 and [time]<2010-1-1
你用的不是mssql么?如果是就记得 这个convert()函数的用法吧,我的例子里已经写清楚了
主要这样可以准确的吧日期数据类型转换成为字符型,这样更方便
而其他的 写法比如 修改时间>='2009-01-01' 可是可以
但是,有的时候会出现一点问题,比如说用between 的时候,可能会没有包含2009-01-01这一天
反正我经常都是用convert()转换成字符形的。
from tb
where year(datefield)=2009