日期:2014-05-18  浏览次数:20463 次

大家来帮我写个存储过程,谢谢了
各位大侠小弟新人,写SQl存储过程不行,现在要完成这个一个要求:就是把2005-03-05这样的一个日期,
转换成:二00五-0三-0五这样的格式,就是这格式,哪位好心的大侠帮我一下,小弟在这谢谢了,感激不尽,小弟急用

------解决方案--------------------
SQL code

go
if OBJECT_ID('pro_test')is not null
drop proc pro_test
go
create proc pro_test @date date
as
create table #test(
id int identity(1,1),
value varchar(2)
)
insert #test(value)
select '一' union all
select '二' union all
select '三' union all
select '四' union all
select '五' union all
select '六' union all
select '七' union all
select '八' union all
select '九'
declare  
      @yearleft varchar(5),@yearright varchar(5),
      @month varchar(5),@day varchar(5)
select @yearleft=value from #test where id=LEFT(LTRIM(year(@date)),1)
select @yearright=value from #test where id=right(LTRIM(year(@date)),1)
select @month=value from #test where id=MONTH(@date)
select @day=value from #test where id=day(@date)
select @yearleft+'00'+@yearright+'-'+'0'+@month+'-'+'0'+@day as newdate

exec pro_test '2005-03-05'
/*
newdate
二00五-0三-0五
*/

--这个存储过程只能处理2010年以下的时间而且月份是在九月份以内,天实在9号之前

------解决方案--------------------
SQL code

declare @x varchar(10)
select @x='2005-03-05'

select replace(replace(replace(replace(
       replace(replace(replace(replace(replace(
       @x,'1','一'),'2','二'),'3','三'),'4','四'),'5','五'),'6','六'),'7','七'),'8','八'),'9','九') x

x
----------------
二00五-0三-0五