PDC_REPORT_CreazioneDB/sql/Collaudo bfdskrepsei02c/procedure/dbo_sp_insertClienteIntoDBNew_Nucleo.sql
2025-06-26 18:47:11 +02:00

46 lines
871 B
Transact-SQL

CREATE PROCEDURE [dbo].[sp_insertClienteIntoDBNew_Nucleo]
@chiavenucleo as BIGINT,
@utente as varchar(13),
@nome as varchar(50) = null
AS
BEGIN
SET NOCOUNT ON;
DECLARE @found as int
--esiste gia?
SELECT @found = count(*)
FROM [dbo].[Cliente]
WHERE [ChiaveNucleo] = @chiavenucleo
AND [Utente] = @utente
IF(@found <= 0) --non esiste
BEGIN
INSERT INTO [dbo].[Cliente]
([DtCreazione]
,[CodEsterno]
,[CodFiscale]
,[Utente]
,[Cognome]
,[Nome]
,[Nominativo]
,[CodiceContratto]
,[ChiaveNucleo])
VALUES
(getdate()
,''
,''
,@utente
,''
,@nome
,@nome
,''
,@chiavenucleo
)
END
ELSE
BEGIN
UPDATE [dbo].[Cliente]
SET [Nominativo] = @nome
,[Nome] = @nome
WHERE [ChiaveNucleo] = @chiavenucleo
AND [Utente] = @utente
END
END