首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

大家来帮小弟我写个存储过程,多谢了

2012-05-16 
大家来帮我写个存储过程,谢谢了各位大侠小弟新人,写SQl存储过程不行,现在要完成这个一个要求:就是把2005-0

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

[解决办法]

SQL code
goif OBJECT_ID('pro_test')is not nulldrop proc pro_testgocreate proc pro_test @date dateascreate table #test(id int identity(1,1),value varchar(2))insert #test(value)select '一' union allselect '二' union allselect '三' union allselect '四' union allselect '五' union allselect '六' union allselect '七' union allselect '八' union allselect '九'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 newdateexec 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','九') xx----------------二00五-0三-0五 

热点排行