日期:2014-05-18  浏览次数:20428 次

求一条 sql 在线等 马上结
请问   怎么select   某年某月的   相关信息?应该怎么写?我的date列是   2007-01-02   上午   10:00:00   这种形式的
select   id,content   from   art   where   date???????
 
我只想   select   精确到月份
select   id,content   from   art   where   date= '2007-01 '   这样不行把?   应该怎么写呢?

------解决方案--------------------
select id,content from art where convert(char(7),date,120)= '2007-01 '
------解决方案--------------------
select id,content from art where date> = '2007-1-1 ' and date < '2007-2-1 '

这样速度快些
------解决方案--------------------
我习惯用DATEDIFF ( datepart , startdate , enddate )


比如:选择 datecol 列值等于 2007-01-02 的行

SELECT * FROM TALBE WHERE DATEDIFF(day,datecol, '2007-01-02 ')=0;

------解决方案--------------------
select * from table where convert(varchar(4),date)+convert(varchar(2),date)= '20073 '
------解决方案--------------------
select id,content from art where date like '2007-01% '
------解决方案--------------------
select id,content from art where convert(varchar(6),date,112)= '200701 '