Pat*_*Pat 3 sql sql-server type-conversion
我需要帮助将一个转换integer成一个varchar.
我正在尝试编写一个接受a ProfileID和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
Run Code Online (Sandbox Code Playgroud)
试试这个.所有这些兴奋的功能都可能是不必要的.
CONVERT(varchar(10),(@CurrentDateTime-@Start_Time),108)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
37654 次 |
| 最近记录: |