Sql 2008:连接两个或多个字符串并在单个记录中显示它们 [英] Sql 2008:concatenate two or more string and display them in a single record

查看:88
本文介绍了Sql 2008:连接两个或多个字符串并在单个记录中显示它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日期时间列,我想添加然后从开始到结束显示所有时间作为一条记录:



例如:

I have a column with date-time and i want to add then display all the time from the start till the end as one record:

For example:

DelayTime:
1900-01-01 02:30:50.000
1900-01-01 03:20:10.000
1900-01-01 02:40:00.000
1900-01-01 00:10:00.000
1900-01-01 03:00:00.000
1900-01-01 06:20:00.000
1900-01-01 05:00:00.000
1900-01-01 01:00:00.000
1900-01-01 01:59:20.000
1900-01-01 00:04:00.000
1900-01-01 00:60:00.000
1900-01-01 00:30:00.000
1900-01-01 08:00:00.000
1900-01-01 09:30:00.000
1900-01-01 10:00:00.000
1900-01-01 03:35:00.000

Then Display as:

DelayTime:
The total time of Delaye
00:00:00

只有,有可能吗?

推荐答案

你不能在DateTime和varchar列上使用SUM。



如果您的最终目标是获得hh:mm:ss中所有datadiff记录的总和,则将差异存储在分钟中: -



You can''t use SUM on a DateTime and varchar column.

If your final goal is to get sum of all datadiff records in hh:mm:ss then stored the difference in minutes as:-

SELECT DATEDIFF(second,CAST('02:32:00' AS DATETIME)
, CAST('03:40:00' AS DATETIME))/60.0 AS MIN_DIFF;





然后用hh执行所有分钟的总和:mm:ss then使用: -





Then to do sum of all minutes in hh:mm:ss then use:-

SELECT CONVERT(CHAR(8), DATEADD(Minute,convert(int, 68), ''00:00:00''), 108)


select''DelayTime:Delaye 00:00:00''的总时间
select ''DelayTime: The total time of Delaye 00:00:00''


这篇关于Sql 2008:连接两个或多个字符串并在单个记录中显示它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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