tsql中的时间跨度值的总和 [英] sum of timespan values in tsql

查看:73
本文介绍了tsql中的时间跨度值的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要将这两个值的总和保存在varchar(12)中的数据库中

第一次:20.04:70:50

第二次:-2.04: 00:00

I want sum of this two value which are saved in database in varchar(12)
first time: 20.04:70:50
second time:-2.04:00:00

推荐答案

请自己帮个忙,不要将它们以VARCHAR格式存储 - 这很浪费,而且它会导致很大的问题,因为你必须解析它永远值得你使用它们。这意味着您有处理垃圾的风险(因为插入数据时数据库中的数据已损坏),这会使您的查询崩溃。

而是将其作为多个Ticks存储在BIGINT中或毫秒,你是数学吗?您可以很容易地将它转换为VARCHAR进行演示,无论如何您都必须这样做才能进行数学运算。



至于你需要做什么你现有的数据,我不知道 - 我不知道你在那里有什么样的基于时间的价值,因为它们似乎不适合任何形式的时间跨度我知道...



现在改变你的数据库设计,之后再成为一个大问题!
Please, do yourself a favour and don't store them in VARCHAR format - it's wasteful, and it causes enormous problems because you have to parse the values ever time you use them. This means that you have the risk of processing rubbish (because the data in the DB was corrupt when you inserted it)which will crash your query.
Instead, store it in a BIGINT as a number of Ticks or milliseconds, and do you maths on that. You can convert that to a VARCHAR for presentation pretty easily, and you would have to do that anyway to do the math.

As to exactly what you need to do with your existing data, I can't tell - I have no idea what kind of time-based values you have there as they don't seem to fit any form of timespan I know...

Change your DB design now, before it becomes a big problem later!


这篇关于tsql中的时间跨度值的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆