Convert DB2 SQL Decimal to DATE

前端 未结 2 669
囚心锁ツ
囚心锁ツ 2020-12-21 07:11

I need to convert Decimal to date. I have a decimal date field that contains data like this :

  • 1,132,009.00 --1/13/2009

  • 7,152,004.00 --7

2条回答
  •  礼貌的吻别
    2020-12-21 08:00

    WITH x(decvalue) AS ( VALUES (DECIMAL(1132009.00)),(DECIMAL(7152004.00)),(DECIMAL(11012005.00)) )
    
    SELECT CAST( 
        LPAD( RTRIM( CHAR( INTEGER( decvalue/1000000 ))), 2, '0' ) || '/' || 
        LPAD( RTRIM( CHAR( MOD( decvalue/10000, 100 ))), 2, '0' )  || '/' ||
        MOD( decvalue, 10000 ) 
    AS CHAR(10)) 
    AS chardateresult
    FROM x
    ;
    

提交回复
热议问题