读书人

求一条 sql 马上结

发布时间: 2012-01-30 21:15:58 作者: rapoo

求一条 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 '

读书人网 >SQL Server

热点推荐