选择语句以HH:MM格式显示分钟 [英] Select statement to display Minutes in HH:MM Format

查看:96
本文介绍了选择语句以HH:MM格式显示分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL Server中有一个表(Table Name -Production).Production表具有一列TimeSpent(Datatype- varchar(25))并存储了Number of minutes.示例60,78,23等.我想在select语句中以HH:MM格式显示TimeSpent.例如,对于60显示01:00,对于78显示01:18,依此类推.请帮助我,我将如何编写此查询.

I am having a table (Table Name -Production) in SQL Server.The Production table have a Column TimeSpent (Datatype- varchar(25)) and stores Number of minutes spent . Example 60,78,23 etc. I want to display TimeSpent in HH:MM Format in a select statement. for example it display 01:00 for 60, 01:18 for 78 and so on. Please help me that how i will write this query.

推荐答案

这将为您提供所需的内容

This will give you what you are looking for

SELECT Convert(varchar(5), DATEADD(minute, Convert(int, YOUR-COLUMN-WITH-MINUTES), ''), 108)



示例:




Example:


SET @TestValue = '130'
SELECT Convert(varchar(5), DATEADD(minute, Convert(int, @TestValue), ''), 108)

-- Result: 02:10


这篇关于选择语句以HH:MM格式显示分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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