简体   繁体   English

在普及SQL中将数字转换为日期

[英]Convert number to Date in Pervasive SQL

I am using Actian SQL Version 12.10.067 and trying to output some values. 我正在使用Actian SQL版本12.10.067并尝试输出一些值。

When running the following query: 运行以下查询时:

SELECT Artikel, Deb, Datum,(BeginVoorraad + Mutatie)AS Stand 
from "Fust"
where Artikel IN (97955)
ORDER BY Artikel DESC

I get the output: 我得到的输出:

Artikel Deb    Datum   Stand
97955   200256 41865.0 68.0

Now I would like to change the Datum number(41865.0) to a real date like 22-08-2018. 现在我想将基准编号(41865.0)更改为真实日期,例如22-08-2018。

I hope someone can help me with the right answer! 我希望有人可以帮助我提供正确的答案!

I am guessing that you want the value convert to the date 2014-08-14 (the value in Excel). 我猜想您要将值转换为日期2014-08-14(Excel中的值)。 If so: 如果是这样的话:

SELECT Artikel, Deb,
       '1899-12-30'::date + Datum * interval '1 day',
       (BeginVoorraad + Mutatie)AS Stand 
FROM "Fust"
WHERE Artikel IN (97955)
ORDER BY Artikel DESC;

The Excel dates are messed up, because it doesn't recognize 1900 as a non-leap year (look it up on Wikipedia). Excel日期被弄乱了,因为它不将1900年识别为非-年(请在Wikipedia上查找)。

If the value is subtly different, just change the base date so you get the value you really want. 如果该值稍有不同,则只需更改基准日期,即可获得您真正想要的值。

EDIT: 编辑:

In Pervasive, I think this does what you want: 在Pervasive中,我认为这可以满足您的需求:

dateadd('day', datum, '1899-12-30')

正确答案是

CAST((Datum -2) AS datetime)

you can try this 你可以试试这个

SELECT Artikel, Deb, cast(Datum as datetime),(BeginVoorraad + Mutatie)AS Stand 
from "Fust"
where Artikel IN (97955)
ORDER BY Artikel DESC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM