或者select * from 数据表 where convert(varchar(4),pubdate)='2002'
select * from 表 where year(pubdate)= 2002
改:select * from 数据表 where convert(varchar(4),pubdate,120)='2002'
select * from 表 where year(attdate)=2002
select * from 表 where year(attdate) = 2002select * from 表 where convert(char(4),attdate,120) = '2002'select * from 表 where datepard(year,attdate) = 2002select * from 表 where datediff(year,'2002-01-01',attdate) = 0
查2001年1月份的: select * from 表 where convert(char(7),attdate,120) = '2002-01'
select * from 表 where year(attdate) = 2002 and month(attdate)=11 --or: select * from 表 where convert(char(7),attdate,120) = '2002-11'
如果要查哪一年哪一月的呢? ---------------------------------------------------------------- 比如查询2002年6月select * from 表 where year(attdate) = 2002 and month(attdate) = 6select * from 表 where convert(char(7),attdate,120) = '2002-06'select * from 表 where datepard(year,attdate) = 2002 and datepard(month,attdate) = 6select * from 表 where datediff(month,'2002-06-01',attdate) = 0
查2001年1月份的: select * from 表 where convert(char(7),attdate,120) = '2002-01' ------------------- 后面那个120表示什么?
select * from 表 where convert(char(7),attdate,120) = '2002-01'
--or:
select * from 表 where convert(char(7),attdate,120) = '2002-11'
----------------------------------------------------------------
比如查询2002年6月select * from 表 where year(attdate) = 2002 and month(attdate) = 6select * from 表 where convert(char(7),attdate,120) = '2002-06'select * from 表 where datepard(year,attdate) = 2002 and datepard(month,attdate) = 6select * from 表 where datediff(month,'2002-06-01',attdate) = 0
select * from 表 where convert(char(7),attdate,120) = '2002-01'
-------------------
后面那个120表示什么?