Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将分钟显示为HH:MM但带有时间数据类型的Sql查询_C#_Sql_Sql Server_Excel_Asp.net Mvc 4 - Fatal编程技术网

C# 将分钟显示为HH:MM但带有时间数据类型的Sql查询

C# 将分钟显示为HH:MM但带有时间数据类型的Sql查询,c#,sql,sql-server,excel,asp.net-mvc-4,C#,Sql,Sql Server,Excel,Asp.net Mvc 4,我有一个sql查询,通过使用此查询将分钟转换为HH:MM格式 declare @tempt table(col1 int) insert into @tempt select 140 union all select 35 select cast (cast((col1)/60 as varchar) + ':' + RIGHT('0' + cast((col1)%60 as varchar),2) as Time) Running from @tempt 输出是 Runnin

我有一个sql查询,通过使用此查询将分钟转换为HH:MM格式

declare @tempt table(col1 int)
insert into @tempt  
select 140
union all
select 35
select cast (cast((col1)/60 as varchar)   
 + ':' + RIGHT('0' + cast((col1)%60 as varchar),2) as Time) Running
  from @tempt
输出是

Running
02:20:00.0000000
00:35:00.0000000
但我想显示为02:20和00:35


我该如何消除这些剩余的零呢?

我们可以这样施展它

SELECT CONVERT(VARCHAR(5),getdate(),108) 

将getdate()替换为datetime对象

这将以
hh:mm:ss
格式在
Time
datatype中给出结果

declare @tempt table(col1 int)
insert into @tempt  
select 140
union all
select 35
select cast (cast((col1)/60 as varchar)   
 + ':' + RIGHT('0' + cast((col1)%60 as varchar),2) as Time(0)) Running
  from @tempt

给出varchar的长度,比如varchar(4)或类似的值。