gpt4 book ai didi

sql-server - SQL Server 将时间戳数据类型转换为十进制

转载 作者:行者123 更新时间:2023-12-02 12:13:34 26 4
gpt4 key购买 nike

一直在尝试解决这个问题,根据 MSDN 上的 Cast 和 Convert 文档,这应该是可能的( http://msdn.microsoft.com/en-us/library/ms187928.aspx )

查看转换表。

enter image description here

我正在运行以下代码:

CREATE TABLE TableName (
ID bigint Identity(1,1),
SomeValue nvarchar(20) not null,
TimestampColumn timestamp not null)

Insert Into TableName (SomeValue)
values ('testing')

SELECT Convert(decimal, TimeStampColumn) from TableName

但是我只是收到以下错误:

Error converting data type timestamp to numeric.

根据文档,这应该是可能的,还是我遗漏了什么?请注意,我还需要转换回相同的时间戳值。

SELECT TimeStampColumn, Convert(timestamp, Convert(decimal, TimeStampColumn)) 
FROM TableName

最后,上面的查询应该呈现相同的值。

最佳答案

试试这个;尽管 MSDN 说这是隐式转换,但实际上不起作用。所以,我正在做的是将其转换为 INT,然后转换为十进制(INT 到十进制无论如何都是隐式的)

select val, CAST((CONVERT(bigint, timestampcol)) as decimal) as 'TS as decimal' 
from teststmp

关于sql-server - SQL Server 将时间戳数据类型转换为十进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10759089/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com