我在嘗試弄清楚如何使此更新正常工作時遇到了一些麻煩。爲什麼此SQL Server UPDATE語句會引發日期時間轉換錯誤?
我想我以前沒有問題,但它似乎現在不工作。我不知道會發生什麼變化。
當我執行此,任何類似的更新語句蒙山這些領域:
UPDATE Clientes
SET CodigoComisionista = 450
WHERE CodigoEmpresa = 1
AND CodigoCliente = '430002801';
我得到一個varchar到日期時間轉換錯誤:
SQL Error (3621): La conversión del tipo de datos varchar en datetime produjo un valor fuera de intervalo
Se terminó la instrucción.
Affected rows: 0 Found rows: 0 Warnings: 0 Duration for 0 of 1 query: 0,000 sec.
望着列類型在那裏我可以」 t明白爲什麼datetime
轉換被拋出。有什麼想法嗎?
select COLUMN_NAME, DATA_TYPE
from INFORMATION_SCHEMA.COLUMNS IC
where TABLE_NAME = 'Clientes' and
(
COLUMN_NAME = 'CodigoEmpresa'
OR COLUMN_NAME = 'CodigoCliente'
OR COLUMN_NAME = 'CodigoComisionista'
)
=====>
"COLUMN_NAME" "DATA_TYPE"
"CodigoEmpresa" "smallint"
"CodigoCliente" "varchar"
"CodigoComisionista" "int"
謝謝!
這是關聯到 「Clientes」 表中的觸發器:
USE [Sage]
GO
/****** Object: Trigger [dbo].[Clientes_SyncIU] Script Date: 15/09/2015 18:11:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[Clientes_SyncIU] ON [dbo].[Clientes] AFTER INSERT, UPDATE
AS
BEGIN
SET NOCOUNT ON;
DECLARE @AppId AS INT
SET @AppId = 0
SELECT @AppId = sysAppId FROM SpidControlSync
WHERE HostProcess = dbo.host_id_sage() AND sysHostName = dbo.host_name_sage()
IF @AppId < 0
BEGIN
RETURN
END
DECLARE @id uniqueidentifier
DECLARE @idPadre uniqueidentifier
DECLARE @linkId uniqueidentifier
DECLARE @oldlinkId uniqueidentifier
DECLARE @tick int
DECLARE @codigoEmpresa int
DECLARE @modifiedDate datetime
DECLARE @accion VarChar(1)
DECLARE @fechaRegistro DATETIME
SET @tick = 1 -- by default
IF EXISTS(SELECT * FROM Inserted) AND EXISTS(SELECT * FROM Deleted) BEGIN
SET @accion = 'U'
END ELSE BEGIN
SET @accion = 'I'
END
DECLARE cur_Inserted CURSOR FOR
SELECT Inserted.IdCliente, ci.sysLinkId, ci.sysModifiedDate , Inserted.CodigoEmpresa FROM Inserted LEFT JOIN Clientes_Sync ci on Inserted.IdCliente=ci.sysGuidRegistro
OPEN cur_Inserted
FETCH NEXT FROM cur_Inserted INTO @id, @linkId, @modifiedDate, @codigoEmpresa
WHILE @@FETCH_STATUS = 0
BEGIN
IF @accion = 'U' AND (@linkId = '00000000-0000-0000-0000-000000000000' OR @linkId IS NULL) BEGIN
SET @linkId = @id
END
-- Call common SYNC Process PROC
EXEC GEN_ProSyncProcess @appid,
@tick output,
'Clientes',
@modifiedDate output,
@fechaRegistro output
-- UPDATE SYNC columns on ClientesGCRMIntegration table.
EXEC GEN_ProSyncMetadataInfo @appID,
@tick,
@modifiedDate,
'Clientes',
'Clientes_Sync',
@id,
'SysGuidRegistro',
@accion,
@fechaRegistro,@codigoEmpresa,@linkId
FETCH NEXT FROM cur_Inserted INTO @id, @linkId, @modifiedDate, @codigoEmpresa END
CLOSE cur_Inserted
DEALLOCATE cur_Inserted
END
可能觸發? – Evk
也許是這樣,我對觸發器一無所知,所以我必須研究這一點。我發佈了關聯的觸發器。 – giorgiline
如果觸發器調用一堆我們看不到的存儲過程,我們無法真正幫助。您應該能夠通過自己執行觸發器定義(使用僞插入/刪除表)來重現錯誤。然後找出導致問題的存儲過程,並查看其正文。繼續以同樣的方式進行。 – hvd