当前位置: 代码迷 >> Sql Server >> 从数据库中搜索时间,只包括年月解决思路
  详细解决方案

从数据库中搜索时间,只包括年月解决思路

热度:38   发布时间:2016-04-27 20:12:34.0
从数据库中搜索时间,只包括年月
数据表中有一个字段   BillPay
                                      2006-11-06   00:00:00
                                      2006-11-16   00:00:00
                                      2007-6-06     00:00:00
                                      2007-6-06     00:00:00
                                      2007-7-06     00:00:00
1、SQL语句怎么写才可以出现让它只显示年月,也就是
                                      2006-11
                                      2007-6
                                      2007-7
2、根据2006-11进行搜索的时候如何出现
                                      2006-11-06   00:00:00
                                      2006-11-16   00:00:00
大家帮忙了。
                                           


------解决方案--------------------
select * from 表
where convert(char(7),BillPay,120)= '2006-11 '
------解决方案--------------------
1
select convert(char(7),BillPay,120) as BillPay from tablename
2
select * from tablename
where convert(char(7),BillPay,120)= '2006-11 '
  相关解决方案