表中字段“日期”的内容为7个字符,如2011-6-,2011-11,请问如何截取月份并转换为数字用于升序排列,这里只截取6,10
解决方案 »
- 一道sql查询问题,不知道怎么写查询语句,求教
- 关于SQL SERVER2000性能的提问
- 向高手请教图书问题
- 请教高手关于Insert Exec 、全局临时表、表变量 的问题
- 数据库名为xxx.xx select * from xxx.xx.表名 报错。请问怎么搞定呀。
- 一个Sql语句的讨论,关于大数据?请高手进
- 修改字符串里的某一个字符 SQL
- windows 2000系统下,mysql报错:在 本地计算机 无法终止mysql服务 错误1053:服务并未及时响应启动或控制请求
- 这个问题怎么解决
- 请问:Access和SQL在开发功能方面有什么不同?
- SQL2005中怎样判断一组数字是否为连续数?
- #1064 - You have an error in your SQL syntax; check the manual that corresponds
select month(getdate())
/*
6
*/
--得到当前时间
select getdate()
/*
2011-06-14 18:35:07.263
*/
--只显示日期
select convert(varchar(10),getdate(),120)
/*
2011-06-14
*/
--只显示到月份
select convert(varchar(7),getdate(),120)
/*
2011-06
*/
insert into tb select '2011-6-' union all select '2011-10'
go
select month(case when right(dt,1)='-' then dt+'1' else dt+'-1' end)m from tb
go
drop table tb
/*
m
-----------
6
10(2 行受影响)*/
不是标准日期了先转为日期类型,然后再去截取convert(varchar(7),convert(datetime,date),120)