integer
을 varchar
으로 변환하는 데 도움이 필요합니다.SQL int를 varchar로 변환
ProfileID
및 Currenttime
을 사용하는 절차를 작성하려고합니다. 이 두 값을 사용하여 profileID
의 시작 시간을 찾고 을 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
오류 메시지가 무엇 –
@hh의 값은 무엇 오류가 발생하는 시점에서? ElideTime에 대한 논리는 간격을 언급하지 않고 있음을 나타냅니다. –
@hh = 1의 값입니다. C 날짜 및/또는 시간을 문자열에서 변환 할 때 변환이 실패했습니다. – Pat