Cra*_*son 3 sql firebird firebird2.5
我有一个表存储一个秒的整数.我想显示它并将其用作时间或日期.
如果我写这个:
Select Cast(ColAmountofSeconds as Time) as ThisTime From MyTable;
Run Code Online (Sandbox Code Playgroud)
同样的:
Select Cast(ColAmountofSeconds as Date) as ThisTime From MyTable;
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
数据类型转换期间发生溢出.字符串"14"的转换错误.
注意"14"是ColAmountofSeconds列中第一行的值.
这在SQL Server中是如此自然,我无法相信我花费了大量时间来搞清楚这一点.
编辑
我简直不敢相信这是答案:
Update MyTable
Set TIMESPENT = time '00:00:00' + ColAmountOfSeconds;
Run Code Online (Sandbox Code Playgroud)
Firebird强制转换功能不支持将数值转换为日期,时间或时间戳.
您可以利用Firebird支持日期和数值之间的算术,因此您可以像这样编写查询:
select dateadd(second, ColAmountOfSeconds, cast('00:00:00' as time))
from myTable;
--or the equivalent:
select cast(cast('2013-01-01' as timestamp) + cast(ColAmountofSeconds as double precision) / 86400 as TIME)
from myTable;
Run Code Online (Sandbox Code Playgroud)