在存储过程中将HH:MM:SS:Msec转换为HH:MM:SS [英] HH:MM:SS:Msec to HH:MM:SS in stored procedure

查看:67
本文介绍了在存储过程中将HH:MM:SS:Msec转换为HH:MM:SS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存储过程,该存储过程会基于这种计算来更新表,并且该计算以列名(日历)-(当前系统日期时间)完成,并将此信息更新为列(TimeSpent)并以Hh显示值:Mm:SS:Msec格式.查询工作正常,但我想以某种方式进行更新,以使花费的时间应仅为HH:MM:SS格式.请帮助我,我如何从所花费的时间中删除该Msec.


I have a stored procedure which update a table based on such calculation and the calculation is done as Column Name (Calendatedate) -( Current System Date Time) and update this information to a column (TimeSpent) and display the value in Hh:Mm:SS:Msec Format. The Query is working fine but i want to update it in such a way so that the Time spent should be only HH:MM:SS Format.Please help me that how i remove that Msec From the time Spent.


CREATE procedure St_Proc_UpdateTimeSpent        
@timeEntryID int,        
@status int output        
as begin         
set nocount on;        
declare @Date dateTime;        
set @Date=GETDATE(); 
	update Production set TimeSpent=(SELECT CONVERT(VARCHAR(20),DateAdd(SS,Datediff(ss,CalendarDate, @Date)%(60*60*24),0),114)),  
	IsTaskCompleted=1       
	where productionTimeEntryID=@timeEntryID         
	set @status=1;        
	return @status;        
end

推荐答案

在CONVERT函数中尝试使用108而不是114来仅获取hh :mm:ss格式.

参考: MSDN:CAST和CONVERT(Transact-SQL) [
Try 108 instead of 114 in the CONVERT function to get only the hh:mm:ss format.

Refer: MSDN: CAST and CONVERT (Transact-SQL)[^]


这篇关于在存储过程中将HH:MM:SS:Msec转换为HH:MM:SS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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