为什么此SQL Server UPDATE语句会引发日期时间转换错误?

时间:2015-09-15 15:43:36

标签: sql sql-server

我在尝试弄清楚如何使此更新正常工作时遇到了一些麻烦。

我认为我之前没有遇到任何问题,但似乎它现在不起作用。我不知道会发生什么变化。

当我执行此操作时,以及与这些字段相关的任何类似更新语句:

UPDATE Clientes 
SET CodigoComisionista = 450 
WHERE CodigoEmpresa = 1 
  AND CodigoCliente = '430002801';

我收到varchar到datetime转换错误:

  

SQL错误(3621):Lacontraióndeltipo de datos varchar en datetime produjo un valor fuera de intervalo
  Seterminólainstrucción。
  受影响的行:0找到的行数:0警告:0 1个查询的0持续时间:0,000秒

查看列类型,我看不出为什么会抛出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

1 个答案:

答案 0 :(得分:-1)

也许UPDATE会创建一个重复的行。