当前位置: 代码迷 >> J# >> ,简单的sql时间查询
  详细解决方案

,简单的sql时间查询

热度:4982   发布时间:2013-02-25 00:00:00.0
在线等,简单的sql时间查询
给定一个不确定的年strYear月strMouth,怎么查出在这时间的所有记录(记录包含时间date)

------解决方案--------------------------------------------------------
select * from table where to_number(to_char(thedate,'yyyy')) = to_number(strYear) and to_number(to_char(thedate,'mm'))=to_number(strMonth)

这是oracle的写法,前提条件是strYear,strMonth都是规范的年和月即数字
------解决方案--------------------------------------------------------
SQL code
select * From Tablewhere year(datecol)=strYearand month(datecol)=strMonth
------解决方案--------------------------------------------------------
year和month返回的是整型数,所在不要在strYear和strMonth的前后加上单引号
------解决方案--------------------------------------------------------
select * From Table
where year(列)=@Year
and month(列)=@Month
------解决方案--------------------------------------------------------
select * from table 
where TableDatetime(列) = Convert(datetime,'strYearstrMouthStrdate')
  相关解决方案