USE [WTNTS] GO /****** Object: StoredProcedure [egm].[serv_spAggiornaStatoOrdine] Script Date: 21/05/2020 17:00:56 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [egm].[serv_spAggiornaStatoOrdine] @codditt varchar(12), @tipodoc varchar(1), @anno smallint, @serie varchar(3), @numdoc varchar(255), @campo varchar(50) AS BEGIN declare @flpres smallint if @campo = 'td_hhegconfcovino' begin begin set @flpres = ( select case when isnull(td_hhegconfcovino,'N') = 'N' then 0 else 1 end as stato from testord WHERE codditt = @codditt and td_tipork = @tipodoc and td_anno = @anno and td_serie = @serie and td_numord = @numdoc) end begin UPDATE testord Set td_hhegconfcovino = 'S', td_hhegconfdatacovino = getdate() WHERE codditt = @codditt and td_tipork = @tipodoc and td_anno = @anno and td_serie = @serie and td_numord = @numdoc and isnull(td_hhegconfcovino,'N') = 'N' end begin select ditta = @codditt, tipo = @tipodoc, serie = @serie, anno = @anno, numero = @numdoc, stato = td_hhegconfcovino, flpres = @flpres from testord WHERE codditt = @codditt and td_tipork = @tipodoc and td_anno = @anno and td_serie = @serie and td_numord = @numdoc end end if @campo = 'td_hhegconfserrano' begin begin set @flpres = ( select case when isnull(td_hhegconfserrano,'N') = 'N' then 0 else 1 end as stato from testord WHERE codditt = @codditt and td_tipork = @tipodoc and td_anno = @anno and td_serie = @serie and td_numord = @numdoc) end begin UPDATE testord Set td_hhegconfcovino = 'S', td_hhegconfserrano = getdate() WHERE codditt = @codditt and td_tipork = @tipodoc and td_anno = @anno and td_serie = @serie and td_numord = @numdoc and isnull(td_hhegconfserrano,'N') = 'N' end begin select ditta = @codditt, tipo = @tipodoc, serie = @serie, anno = @anno, numero = @numdoc, stato = td_hhegconfserrano, flpres = @flpres from testord WHERE codditt = @codditt and td_tipork = @tipodoc and td_anno = @anno and td_serie = @serie and td_numord = @numdoc end end END GO