本文介绍了将DB2 SQL小数转换为DATE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将小数转换为日期。我有一个包含如下数据的十进制日期字段:
- 1,132,009.00 --1 / 13/2009
- 7,152,004.00 - 7/15/2004
-
11,012,005.00 --11 / 01/2005
/ p>
我想读为 xx / xx / xxxx
有没有在select语句中使用SQL命令或DB2逻辑?
从table1中选择column1;
解决方案
($($)
)($($($($)$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ (RTRIM(CHAR(MOD(decvalue / 10000,100))),2,'0')||' /'||
MOD(decvalue,10000)
AS CHAR(10))
AS chardateresult
FROM x
;
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/15/2004
11,012,005.00 --11/01/2005
etc
I would like it to read as xx/xx/xxxx.
Is there anyway to do this with SQL commands or DB2 logic in a select statement?
SELECT column1 from table1 ;
解决方案
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
;
这篇关于将DB2 SQL小数转换为DATE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!