buena tarde... Tengo un error al querer ejecutar un Stored Procedure en SQL server, les muestro el codigo de mi SP:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_WARNINGS OFF
GO
ALTER PROC [dbo].[spkof_DSD_ST_STATUS_H-TourStatusHistoryRecordingTourStatus] AS
begin
declare @dteIni datetime,
@sProcesoNom varchar(100),
@sMensaje varchar(300),
@iRegHistoria integer,
@iRegDelta integer,
@iError integer,
@iUpdate integer,
@iInsert integer = 0,
@rowcount integer = 0,
@TimezoneName varchar(max) = 'Central Standard Time (Mexico)';
set @dteIni = SWITCHOFFSET(getdate(), Datediff( MINUTE, getdate() at time zone @TimezoneName, getdate() ))
set @sProcesoNom = 'spKof_DSD_ST_STATUS_H-TourStatusHistoryRecordingTourStatus'
-- Registra el inicio del proceso en la bitácora
insert into kofBitacora (ProcesoNom, FechaHoraIni, FechaHoraFin, MensajeDsc) values (@sProcesoNom, @dteIni, '99991231', 'INICIADO....')
-- Calcula la cantidad de registros a procesar
set @iRegHistoria = (select count(*) from [cadsum].[DSD_ST_STATUS_H-TourStatusHistoryRecordingTourStatus])
set @iRegDelta = (select count(*) from [dbo].[tmpDSD_ST_STATUS_H-TourStatusHistoryRecordingTourStatus])
set @sMensaje = ' registros: [ ' + convert(varchar(10), @iRegHistoria) + ' Historia; ' + convert(varchar(10), @iRegDelta) + ' Delta]'
update kofBitacora set MensajeDsc = 'Actualizando... ' + @sMensaje where ProcesoNom = @sProcesoNom and FechaHoraIni = @dteIni
update H
set
--============= CAMPOS NO LLAVES =============
H.[STATUS_ID] = cast(N.[STATUS_ID] as varchar(8)),
H.[IDATE] = convert(date, case when N.[IDATE] = '00000000' OR N.[IDATE] = '' then '19000101' else N.[IDATE] end, 112),
H.[ITIME] = cast(format(cast(case when isnumeric(N.[ITIME]) <> 1 or N.[ITIME] = '240000' then 0 else N.[ITIME] end as int), '00:00:00') as time),
H.[CANCELED] = cast(N.[CANCELED] as varchar(1)),
H.[MAN_EXEC] = cast(N.[MAN_EXEC] as varchar(1))
--============================================
from [cadsum].[DSD_ST_STATUS_H-TourStatusHistoryRecordingTourStatus] H inner join [dbo].[tmpDSD_ST_STATUS_H-TourStatusHistoryRecordingTourStatus] N
--============= CAMPOS LLAVES ================
on H.[TOURID] = cast(N.[TOURID] as varchar(12))
and H.[COUNTER] = cast(N.[COUNTER] as varchar(8))
--============================================
--============= CAMPOS DEFAULT ===============
and H.[MAND] = cast(N.[MAND] as varchar(3))
and H.[Mandante] = cast(N.[Mandante] as varchar(3))
--============================================
OPTION (LABEL = 'spKof_DSD_ST_STATUS_H-TourStatusHistoryRecordingTourStatus_update01')
-- Declara el @@RowCount
select top 1 @rowcount = row_count
from [sys].[dm_pdw_request_steps] s, [sys].[dm_pdw_exec_requests] r
where r.request_id = s.request_id
and row_count > -1
and operation_type = 'OnOperation'
and r.[label] = 'spKof_DSD_ST_STATUS_H-TourStatusHistoryRecordingTourStatus_update01'
order by r. [end_time] desc;
select @iError = @@ERROR, @iUpdate = @rowcount
update kofBitacora set MensajeDsc = 'Insertando... ' + @sMensaje where ProcesoNom = @sProcesoNom and FechaHoraIni = @dteIni;
insert into [cadsum].[DSD_ST_STATUS_H-TourStatusHistoryRecordingTourStatus]
select
--============= CAMPOS LLAVES ================
cast([TOURID] as varchar(12)) as [TOURID]
,cast([COUNTER] as varchar(8)) as [COUNTER]
--============================================
--============= CAMPOS NO LLAVES =============
,cast([STATUS_ID] as varchar(8)) as [STATUS_ID]
,convert(date, case when [IDATE] = '00000000' OR [IDATE] = '' then '19000101' else [IDATE] end, 112) as [IDATE]
,cast(format(cast(case when isnumeric([ITIME]) <> 1 or [ITIME] = '240000' then 0 else [ITIME] end as int), '00:00:00') as time) as [ITIME]
,cast([CANCELED] as varchar(1)) as [CANCELED]
,cast([MAN_EXEC] as varchar(1)) as [MAN_EXEC]
--============================================
--============= CAMPOS DEFAULT ===============
,cast([MAND] as varchar(3)) as [MAND]
,cast([Mandante] as varchar(3)) as [Mandante]
--============================================
from [dbo].[tmpDSD_ST_STATUS_H-TourStatusHistoryRecordingTourStatus] N
where not exists
(select * from [cadsum].[DSD_ST_STATUS_H-TourStatusHistoryRecordingTourStatus] H
where 1 = 1
--============= CAMPOS LLAVES ================
and H.[TOURID] = cast(N.[TOURID] as varchar(12))
and H.[COUNTER] = cast(N.[COUNTER] as varchar(8))
--============================================
--============= CAMPOS DEFAULT ===============
and H.[MAND] = cast(N.[MAND] as varchar(3))
and H.[Mandante] = cast(N.[Mandante] as varchar(3))
--============================================
)
OPTION (LABEL = 'spKof_DSD_ST_STATUS_H-TourStatusHistoryRecordingTourStatus_insert01');
select top 1 @rowcount = row_count
from [sys].[dm_pdw_request_steps] s, [sys].[dm_pdw_exec_requests] r
where r.request_id = s.request_id
and row_count > -1
and operation_type = 'OnOperation'
and r.[label] = 'spKof_DSD_ST_STATUS_H-TourStatusHistoryRecordingTourStatus_insert01'
order by r. [end_time] desc;
select @iError = @iError + @@ERROR, @iInsert = @rowcount
If @iError <> 0 set @sMensaje = 'ERROR ' + convert(varchar(10), @iError) + 'al procesar ' + @sMensaje
else
begin
set @sMensaje = 'OK, registros procesados: [ ' +
convert(varchar(10), @iRegHistoria) + ' Historia; ' +
convert(varchar(10), @iRegDelta) + ' Delta; ' +
convert(varchar(10), @iUpdate) + ' Modificados; ' +
convert(varchar(10), @iInsert) + ' Nuevos]';
end
update kofBitacora
set MensajeDsc = @sMensaje,
FechaHoraFin = SWITCHOFFSET(getdate(), Datediff( MINUTE, getdate() at time zone @TimezoneName, getdate() ))
where ProcesoNom = @sProcesoNom and FechaHoraIni = @dteIni;
end
SET ANSI_WARNINGS ON
GO
Al ejecutar ese SP de la siguiente manera:
exec [dbo].[spkof_DSD_ST_STATUS_H-TourStatusHistoryRecordingTourStatus]
Marca el siguiente error de insercion de datos de una tabla ([dbo].[tmpDSD_ST_STATUS_H-TourStatusHistoryRecordingTourStatus]) a otra tabla final ([cadsum].[DSD_ST_STATUS_H-TourStatusHistoryRecordingTourStatus]):
Investigando sobre este error, encuentro a que se debe porque el numero de caracteres de mis datos es superior al tamaño de mi columna, pero mis datos son menores al tamaño de mis columnas.
Entonces por eso en el SP puse las funciones "SET ANSI_WARNINGS OFF" y "SET ANSI_WARNINGS ON" para anular el error que marca al ejecutarlo.
Pero marca el siguiente error:
Lo que quisiera saber es en donde puedo colocar estas funciones "SET ANSI_WARNINGS OFF" y "SET ANSI_WARNINGS ON" en mi SP para poder ejecutar correctamente mi SP.
Espero haberme explicado bien. Cualquier cosa estaré al pendiente
Saludos.