0

下面是我的表格包含持续时间为 HH:MM:SS

我的桌子

我可以将其转换为秒

SELECT  (SUBSTRING(CAST('00:01:15' AS NVARCHAR(MAX)),1,2) * 360) 
+ (SUBSTRING(CAST('00:01:15' AS NVARCHAR(MAX)),4,2) * 60) 
+  SUBSTRING(CAST('00:01:15' AS NVARCHAR(MAX)),7,2)

现在我需要通过读取每一行记录来将该表更新为几秒钟?

就像我需要每一行而不是'00:01:15'@DURATIONINSECONDS

4

1 回答 1

0

Try like below

If your table have value like this

Table1

DurationInSeconds
00:01:15    
00:00:15    
00:01:16    
00:01:17

and you want to Update the field DurationInSeconds into Seconds...

then just try like the below query....

update Table1 set DurationInSeconds = (SUBSTRING(CAST(DurationInSeconds AS NVARCHAR(MAX)),1,2) * 360) + (SUBSTRING(CAST(DurationInSeconds AS NVARCHAR(MAX)),4,2) * 60) +  SUBSTRING(CAST(DurationInSeconds AS NVARCHAR(MAX)),7,2)

then it give the Result like below

SELECT * from Table1

DurationInSeconds
75
15
76
77
于 2013-01-31T10:29:32.360 回答