并提前感谢
我有一个非常基本的存储过程,可以在表中插入一行。直到今天它一直完美无缺
这是脚本
(
@emp varchar(16),
@logdate date,
@logtime time,
@term char(20),
@SSID char(16)
)
AS
INSERT INTO AccessLog (EmployeeID, LogDate, LogTime, TerminalID, InOut, ChangedBy)
VALUES (@emp, @logdate, @logtime, @term, 3, @SSID)
当 5118 的字符串传递给它时,插入将失败。在此插入完成后,有几个触发器会触发。
这是奇怪的部分。您可以为@emp
变量传递任何其他数字,它工作得很好,但传递它 5118,它会失败。
我收到的错误如下:
消息 241,级别 16,状态 1,过程 UpdateTimeWorked,第 27 行
从字符串转换日期和/或时间时转换失败。
这是失败的过程 - 突出显示的行是第 27 行
TRIGGER [dbo].[UpdateTimeWorked] ON [dbo].[TimeLog]
FOR UPDATE
AS
SET NOCOUNT ON
DECLARE @ID int;
DECLARE @RCDIDIN int;
DECLARE @RCDIDOUT int;
DECLARE @ComboIn datetime;
DECLARE @ComboOut datetime;
SELECT @ID = ID FROM INSERTED;
SELECT @ComboIn = LoginCombo FROM INSERTED;
SELECT @ComboOut = LogoutCombo FROM INSERTED;
SELECT @RCDIDIN = RCDIDIN FROM INSERTED;
SELECT @RCDIDOUT = RCDIDOUT FROM INSERTED;
**IF ( UPDATE(LogoutCombo))**
BEGIN
IF (@RCDIDOUT != 0)
BEGIN
UPDATE TimeLog
SET LogOutRND = (select CAST(dbo.roundtime(LogOutRND,0.25) AS TIME))
WHERE ID = @ID
UPDATE TimeLog
SET LogOutComboRND = CAST(CAST(LogOutDate AS DATE) AS SMALLDATETIME) + CAST(LogOutRND AS TIME)
WHERE ID = @ID
UPDATE TimeLog
SET TimeWorked = dbo.gettime(DATEDIFF(ss,LogInComboRND,LogoutComboRND))
WHERE ID = @ID AND LogInEntered = 1 AND LogOutEntered = 1
UPDATE TimeLog
SET TimeWorked = (select CAST(dbo.roundtime(TimeWorked,0.25) AS TIME)), Rounded = 1
WHERE ID = @ID AND LogInEntered = 1 AND LogOutEntered = 1
END
END
IF ( UPDATE(LoginCombo))
BEGIN
IF (@RCDIDIN != 0)
BEGIN
UPDATE TimeLog
SET LogInRND = (select CAST(dbo.roundtime(LogInRND,0.25) AS TIME))
WHERE ID = @ID
UPDATE TimeLog
SET LogInComboRND = CAST(CAST(LogInDate AS DATE) AS SMALLDATETIME) + CAST(LogInRND AS TIME)
WHERE ID = @ID
UPDATE TimeLog
SET TimeWorked = dbo.gettime(DATEDIFF(ss,LogInComboRND,LogoutComboRND))
WHERE ID = @ID AND LogInEntered = 1 AND LogOutEntered = 1
UPDATE TimeLog
SET TimeWorked = (select CAST(dbo.roundtime(TimeWorked,0.25) AS TIME)), Rounded = 1
WHERE ID = @ID AND LogInEntered = 1 AND LogOutEntered = 1
END
END
GO
我完全无法想出为什么这不起作用。
有人有想法么?
正如我所说,将@emp 的任何其他条目传递给它,它会运行良好。我什至可以通过它'5118',它会工作,但不是 5118。