我需要帮助将 an 转换integer
为varchar
.
我正在尝试编写一个包含 aProfileID
和 a的程序Currenttime
;使用这两个值,它会找到 的开始时间并从中
profileID
减去并返回。currenttime
starttime
hours:minutes:seconds
我做错了什么,有没有更好的方法来写这个?
谢谢。
CREATE PROCEDURE [dbo].[CalculateElaspedTime]
-- Add the parameters for the stored procedure here
@ProfileID nvarchar(10),
@CurrentDateTime datetime = ''
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
if @CurrentDateTime = CAST('' as datetime)
set @CurrentDateTime = GETDATE()
DECLARE @StartTime datetime;
DECLARE @ElaspedTime time;
DECLARE @hh int;
DECLARE @mm int;
DECLARE @ss int;
Declare @TimeString varchar
set @StartTime = (Select top 1 [DateTime] From Log WHERE ProfileID = @ProfileID);
set @hh = DateDiff(hour,@StartTime,@CurrentDateTime);
set @mm = DateDiff(minute,@StartTime,@CurrentDateTime)-60*@hh;
set @ss = DateDiff(second,@StartTime,@CurrentDateTime)-60*@mm;
set @TimeString = (Select CAST(@hh as varchar)); -- Fails Here
set @ElaspedTime = convert(datetime, cast(@hh as varchar) + ':' + cast(@mm as varchar) + ':' + cast(@ss as varchar));
INSERT INTO Log (ElaspedTime) Values (@ElaspedTime);
END