|
发表于 2013-5-20 10:52:37
|
显示全部楼层
--假设数据字段为字符型
declare @tab table (date varchar(50))
insert @tab
select '2013-04-15' union all
select '2012-11-12' union all
select '2013-05-20';
--测试代码
select substring(date,6,2) as 月份 from @tab
/* 测试结果
(所影响的行数为 3 行)
月份
----
04
11
05
(所影响的行数为 3 行)*/
--假设数据字段为日期型
declare @tab1 table (date datetime)
insert @tab1
select '2013-04-15' union all
select '2012-11-12' union all
select '2013-05-20';
--测试代码
select substring(convert(varchar(10),date,112),5,2) as 月份 from @tab1
/* 测试结果
(所影响的行数为 3 行)
月份
----
04
11
05
(所影响的行数为 3 行)*/ |
|