При выполнении процедуры появляется ошибка
CREATE PROCEDURE Login_Logout_Rpt AS BEGIN DECLARE @SDOW DATETIME SET @SDOW= (SELECT DATEADD(DAY, 2 - DATEPART(WEEKDAY, GETDATE()), CAST(GETDATE() AS DATE))) PRINT @SDOW SET NOCOUNT ON ;WITH CteUserInOut(RowNUm,DtDate,Access_ID,Access_Name,Access_Profile,Access_Type,Access_Country,Access_SourceIP,Access_SourceHost,mnmUser,DtTime,InOut) AS ( SELECT ROW_NUMBER() OVER (ORDER BY UserInOut.mnmUser,UserInOut.DtTime) AS RowNUm ,CAST(UserInOut.DtTime AS DATE)AS DtDate ,DealerAddMrv.mnmUser as Access_ID ,DealerAddMrv.mnmUserName as Access_Name ,DealerAddMrv.mnmRole as Access_Profile ,UserInOut.mnmUserAccessType as Access_Type ,'IND' AS Access_Country ,CASE WHEN CHARINDEX(',',UserInOut.mnmIPDetails,1) > 0 THEN SUBSTRING(UserInOut.mnmIPDetails,1,CHARINDEX(',',UserInOut.mnmIPDetails,1)-1) ELSE UserInOut.mnmIPDetails END As Access_SourceIP, 'NULL' as Access_SourceHost ,UserInOut.InOut ,UserInOut.mnmUser ,UserInOut.DtTime FROM dbo.UserInOut INNER JOIN dbo.DealerAddMrv ON DealerAddMrv.mnmUser = UserInOut.mnmUser WHERE UserInOut.DtTime >= @SDOW ) SELECT U1.Access_ID ,U1.Access_Name ,U1.Access_Profile ,U1.Access_Type ,U1.Access_Country ,U1.Access_SourceIP ,U1.Access_SourceHost ,U1.DtTime AS Access_LoginTimeStamp ,U2.DtTime AS Access_LogOutTimeStamp FROM (SELECT * FROM CteUserInOut WHERE InOut = 'IN') AS U1 JOIN (SELECT * FROM CteUserInOut WHERE InOut = 'OUT' ) AS U2 ON U2.RowNUm = U1.RowNUm+1 AND U1.mnmUser = U2.mnmUser AND U1.DtDate = U2.DtDate END GO exec Login_Logout_Rpt
Что я уже пробовал:
я создал процедуру, как показано ниже
CREATE PROCEDURE Login_Logout_Rpt AS BEGIN DECLARE @SDOW DATETIME SET @SDOW= (SELECT DATEADD(DAY, 2 - DATEPART(WEEKDAY, GETDATE()), CAST(GETDATE() AS DATE))) PRINT @SDOW SET NOCOUNT ON ;WITH CteUserInOut(RowNUm,DtDate,Access_ID,Access_Name,Access_Profile,Access_Type,Access_Country,Access_SourceIP,Access_SourceHost,mnmUser,DtTime,InOut) AS ( SELECT ROW_NUMBER() OVER (ORDER BY UserInOut.mnmUser,UserInOut.DtTime) AS RowNUm ,CAST(UserInOut.DtTime AS DATE)AS DtDate ,DealerAddMrv.mnmUser as Access_ID ,DealerAddMrv.mnmUserName as Access_Name ,DealerAddMrv.mnmRole as Access_Profile ,UserInOut.mnmUserAccessType as Access_Type ,'IND' AS Access_Country ,CASE WHEN CHARINDEX(',',UserInOut.mnmIPDetails,1) > 0 THEN SUBSTRING(UserInOut.mnmIPDetails,1,CHARINDEX(',',UserInOut.mnmIPDetails,1)-1) ELSE UserInOut.mnmIPDetails END As Access_SourceIP, 'NULL' as Access_SourceHost ,UserInOut.InOut ,UserInOut.mnmUser ,UserInOut.DtTime FROM dbo.UserInOut INNER JOIN dbo.DealerAddMrv ON DealerAddMrv.mnmUser = UserInOut.mnmUser WHERE UserInOut.DtTime >= @SDOW ) SELECT U1.Access_ID ,U1.Access_Name ,U1.Access_Profile ,U1.Access_Type ,U1.Access_Country ,U1.Access_SourceIP ,U1.Access_SourceHost ,U1.DtTime AS Access_LoginTimeStamp ,U2.DtTime AS Access_LogOutTimeStamp FROM (SELECT * FROM CteUserInOut WHERE InOut = 'IN') AS U1 JOIN (SELECT * FROM CteUserInOut WHERE InOut = 'OUT' ) AS U2 ON U2.RowNUm = U1.RowNUm+1 AND U1.mnmUser = U2.mnmUser AND U1.DtDate = U2.DtDate END
при выполнении этой процедуры появляется ошибка, как показано ниже
Msg 241, Уровень 16, состояние 1, процедура Login_Logout_Rpt, строка 9 преобразование не удалось при преобразовании даты и/или времени из символьной строки.
Richard MacCutchan
Какую часть сообщения об ошибке вы не понимаете?
Bimith Kunhiraman
я понял часть ошибки но не могу разобраться в ней не могли бы вы мне помочь