首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

一个关于日期查询的简单SQL?该如何处理

2012-01-29 
一个关于日期查询的简单SQL?createtabletest(idchar(3),rqdatetime)insertintotestselect1 , 2007-1-1inse

一个关于日期查询的简单SQL?
create   table   test
(
id   char(3),
rq   datetime
)
insert   into   test   select   '1 ', '2007-1-1 '
insert   into   test   select   '2 ', '2007-1-1 '
insert   into   test   select   '3 ', '2007-1-2 '
insert   into   test   select   '1 ', '2007-2-1 '
insert   into   test   select   '1 ', '2007-2-2 '
insert   into   test   select   '1 ', '2007-2-3 '
drop   table   test
/*
要求按照年份和月份查询
例如:查询2007年1月份
'1 ', '2007-1-1 '
'2 ', '2007-1-1 '
'3 ', '2007-1-2 '
查询2007年2月份
'1 ', '2007-2-1 '
'1 ', '2007-2-2 '
'1 ', '2007-2-3 '
依次类推。。。
*/

[解决办法]
select * from test
where year(rq) = @年份参数 and month(rq) = @月份参数

热点排行
Bad Request.