DROP PROCEDURE LD0_A01_INSERT
GO
CREATE PROCEDURE LD0_A01_INSERT
                                   (@PI_PNR        AS VARCHAR(12),
                                    @PI_NAMN       AS VARCHAR(180),
                                    @PI_ADRESS     AS VARCHAR(70),
									@PI_COADRESS     AS VARCHAR(70),
                                    @PI_POSTNR     AS VARCHAR(16),
                                    @PI_ORT        AS VARCHAR(64),
									@PI_HEMTEL	   AS VARCHAR(32), 
									@PI_ARBTEL	   AS VARCHAR(32), 
									@PI_MOBIL		AS VARCHAR(32),
									@PI_EPOSTHEM	AS VARCHAR(100),
									@PI_ADRSKYDD   AS DECIMAL(1),
									@PI_HEMLIGTFN	AS DECIMAL(1),
                                    @PI_CIVKOD		AS DECIMAL(9),
									@PI_CIVDAT     AS VARCHAR(8),
									@PI_MEDBSKAP   AS DECIMAL(9),
                                    @PI_MEDBDAT    AS VARCHAR(8),
									@PI_FODFORS	   AS DECIMAL(9),									
									@PI_FODLAND	   AS DECIMAL(9),									
									@PI_OMRADE	   AS DECIMAL(9),
									@PI_FOLKFORS   AS DECIMAL(9),
									@PI_FOLKLAN	   AS DECIMAL(9),
									@PI_FOLKKOM	   AS DECIMAL(9),
									@PI_FOLKDAT	   AS VARCHAR(8),
									@PI_AVREGORS   AS DECIMAL(9),
									@PI_AVREGDAT   AS VARCHAR(8),
									@PI_NYCKKOD    AS VARCHAR(24),
									@PI_MODMAL     AS DECIMAL(9),
									@PI_KOMSPRAK	AS DECIMAL(9),
									@PI_KOMSPRAK2	AS DECIMAL(9),
									@PI_KOMSPRAK3	AS DECIMAL(9),
									@PI_INVANDAT	AS VARCHAR(8),
									@PI_TOLKBEHOV	AS DECIMAL(1),
									@PI_MINSIDA		AS DECIMAL(1),
									@PI_KADRESS	   AS VARCHAR(70), 
									@PI_KCOADR	   AS VARCHAR(70), 
									@PI_KPOSTNR     AS VARCHAR(5),
									@PI_KORT     AS VARCHAR(27),
									@PI_KHEMTEL	   AS VARCHAR(18),
									@PI_KUATDAT	   AS VARCHAR(8), 
									@PI_KFLYKTING	   AS DECIMAL(1),	
									@PI_SMSAVIS	   AS DECIMAL(1),	
									@PI_MAILAVIS	   AS DECIMAL(1),	
									@PI_LCMEDDELANDE AS DECIMAL(1),
									@PI_MINSIDA_VUXNA AS DECIMAL(1),
									
									@PI_UPDDAT     AS VARCHAR(8),
                                    @PI_UPDSIGN    AS VARCHAR(10))
AS
BEGIN

 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Personnr') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Personnr', ' ', @PI_PNR, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Namn') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Namn', ' ', @PI_NAMN, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Adress') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Adress', ' ', @PI_ADRESS, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='C/O Adress') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'C/O Adress', ' ', @PI_COADRESS, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Postnr') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Postnr', ' ', @PI_POSTNR, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Ort') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Ort', ' ', @PI_ORT, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Hemtelefon') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Hemtelefon', ' ', @PI_HEMTEL, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Arbetstelefon') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Arbetstelefon', ' ', @PI_ARBTEL, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Mobil') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Mobil', ' ', @PI_MOBIL, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='E-post hem') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'E-post hem', ' ', @PI_EPOSTHEM, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Adresskydd') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Adresskydd', ' ', @PI_ADRSKYDD, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Hemligt telefonnummer') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Hemligt telefonnummer', ' ', @PI_HEMLIGTFN, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Civilståndskod') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Civilståndskod', ' ', @PI_CIVKOD, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Datum för Civilståndsändring') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Datum för Civilståndsändring', ' ', @PI_CIVDAT, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Medborgarskap') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Medborgarskap', ' ', @PI_MEDBSKAP, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Medborgarskap datum') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Medborgarskap datum', ' ', @PI_MEDBDAT, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Födelseförsamling') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Födelseförsamling', ' ', @PI_FODFORS, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Födelseland') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Födelseland', ' ', @PI_FODLAND, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Område') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Område', ' ', @PI_OMRADE, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Församlingstillhörighet') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Församlingstillhörighet', ' ', @PI_FOLKFORS, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Län') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Län', ' ', @PI_FOLKLAN, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Hemkommun') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Hemkommun', ' ', @PI_FOLKKOM, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Folkbokföringsdatum') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Folkbokföringsdatum', ' ', @PI_FOLKDAT, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Avregistreringsorsak') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Avregistreringsorsak', ' ', @PI_AVREGORS, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Avregistreringsdatum') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Avregistreringsdatum', ' ', @PI_AVREGDAT, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Nyckelkod') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Nyckelkod', ' ', @PI_NYCKKOD, @PI_UPDDAT, @PI_UPDSIGN, ' ')   
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Modersmål') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Modersmål', ' ', @PI_MODMAL, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Kommunikationsspråk') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Kommunikationsspråk', ' ', @PI_KOMSPRAK, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Kommunikationsspråk 2') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Kommunikationsspråk 2', ' ', @PI_KOMSPRAK2, @PI_UPDDAT, @PI_UPDSIGN, ' ')                       
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Kommunikationsspråk 3') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Kommunikationsspråk 3', ' ', @PI_KOMSPRAK3, @PI_UPDDAT, @PI_UPDSIGN, ' ') 
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Invandringsdatum') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Invandringsdatum', ' ', @PI_INVANDAT, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Tolkbehov') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Tolkbehov', ' ', @PI_TOLKBEHOV, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Min Sida') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Min Sida', ' ', @PI_MINSIDA, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Klientens Adress') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Klientens Adress', ' ', @PI_KADRESS, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Klientens C/O Adress') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Klientens C/O Adress', ' ', @PI_KCOADR, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Klientens Postnr') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Klientens Postnr', ' ', @PI_KPOSTNR, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Klientens Ort') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Klientens Ort', ' ', @PI_KORT, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Klientens Hemtelefon') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Klientens Hemtelefon', ' ', @PI_KHEMTEL, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Klientens Datum för Uppehålls- och arbetstillstånd') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Klientens Datum för Uppehålls- och arbetstillstånd', ' ', @PI_KUATDAT, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Klienten Flykting') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Klienten Flykting', ' ', @PI_KFLYKTING, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='SMS Notifiering') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'SMS Notifiering', ' ', @PI_SMSAVIS, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Epost Notifiering') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Epost Notifiering', ' ', @PI_MAILAVIS, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Lifecare meddelande') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Lifecare meddelande', ' ', @PI_LCMEDDELANDE, @PI_UPDDAT, @PI_UPDSIGN, ' ')
 IF ((SELECT COUNT(*) FROM LD0P0A01 A01 WHERE A01.PNR = @PI_PNR AND COLNAME='Min Sida Vuxen') = 0)
  INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
  VALUES (@PI_PNR, 'Min Sida Vuxen', ' ', @PI_MINSIDA_VUXNA, @PI_UPDDAT, @PI_UPDSIGN, ' ')
END
GO

DROP TRIGGER LD0T0A01_INS
GO
CREATE TRIGGER LD0T0A01_INS ON LD0P0A
FOR INSERT
AS
IF ((SELECT COUNT(*) FROM LD0P0A01 WHERE PNR IN (SELECT PNR FROM INSERTED)) > 0)
 DELETE FROM LD0P0A01 WHERE PNR IN (SELECT PNR FROM INSERTED INS)
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Personnr', ' ', PNR, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Namn', ' ', NAMN, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Adress', ' ', ADRESS, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'C/O Adress', ' ', COADR, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Postnr', ' ', POSTNR, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Ort', ' ', ORT, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Hemtelefon', ' ', HEMTEL, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Arbetstelefon', ' ', ARBTEL, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Mobil', ' ', MOBIL, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'E-post hem', ' ', EPOSTHEM, UPDDAT, UPDSIGN, ' ' FROM INSERTED  
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Adresskydd', ' ', ADRSKYDD, UPDDAT, UPDSIGN, ' ' FROM INSERTED  
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Hemligt telefonnummer', ' ', HEMLIGTFN, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Civilståndskod', ' ', CIVKOD, UPDDAT, UPDSIGN, ' ' FROM INSERTED 
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Datum för Civilståndsändring', ' ', CIVDAT, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Medborgarskap', ' ', MEDBSKAP, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Medborgarskap datum', ' ', MEDBDAT, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Födelseförsamling', ' ', FODFORS, UPDDAT, UPDSIGN, ' ' FROM INSERTED 
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Födelseland', ' ', FODLAND, UPDDAT, UPDSIGN, ' ' FROM INSERTED   
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Område', ' ', OMRADE, UPDDAT, UPDSIGN, ' ' FROM INSERTED 
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Församlingstillhörighet', ' ', FOLKFORS, UPDDAT, UPDSIGN, ' ' FROM INSERTED 
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Län', ' ', FOLKLAN, UPDDAT, UPDSIGN, ' ' FROM INSERTED 
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Hemkommun', ' ', FOLKKOM, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Folkbokföringsdatum', ' ', FOLKDAT, UPDDAT, UPDSIGN, ' ' FROM INSERTED  
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Avregistreringsorsak', ' ', AVREGORS, UPDDAT, UPDSIGN, ' ' FROM INSERTED   
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Avregistreringsdatum', ' ', AVREGDAT, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Nyckelkod', ' ', NYCKKOD, UPDDAT, UPDSIGN, ' ' FROM INSERTED   
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Modersmål', ' ', MODMAL, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Kommunikationsspråk', ' ', KOMSPRAK, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Kommunikationsspråk 2', ' ', KOMSPRAK2, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Kommunikationsspråk 3', ' ', KOMSPRAK3, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Invandringsdatum', ' ', INVANDAT, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Tolkbehov', ' ', TOLKBEHOV, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Min Sida', ' ', MINSIDA, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Klientens Adress', ' ', KADRESS, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Klientens C/O Adress', ' ', KCOADR, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Klientens Postnr', ' ', KPOSTNR, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Klientens Ort', ' ', KORT, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Klientens Hemtelefon', ' ', KHEMTEL, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Klientens Datum för Uppehålls- och arbetstillstånd', ' ', KUATDAT, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Klienten Flykting', ' ', KFLYKTING, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'SMS Notifiering', ' ', CASE WHEN SMSAVIS=1 THEN 'Ja' ELSE 'Nej' END, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Epost Notifiering', ' ', CASE WHEN MAILAVIS=1 THEN 'Ja' ELSE 'Nej' END, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Lifecare meddelande', ' ', CASE WHEN LCMEDDELANDE=1 THEN 'Ja' ELSE 'Nej' END, UPDDAT, UPDSIGN, ' ' FROM INSERTED
INSERT INTO LD0P0A01 (PNR, COLNAME, OLDVALUE, NEWVALUE, UPDDAT, UPDSIGN, DATASOURCE) 
SELECT PNR, 'Min Sida Vuxen', ' ', MINSIDA_VUXNA, UPDDAT, UPDSIGN, ' ' FROM INSERTED
GO

DROP TRIGGER LD0T0A01_UPD
GO
CREATE TRIGGER LD0T0A01_UPD ON LD0P0A
FOR UPDATE
AS
IF UPDATE(PNR) OR
   UPDATE(NAMN) OR
   UPDATE(ADRESS) OR
   UPDATE(COADR) OR
   UPDATE(POSTNR) OR
   UPDATE(ORT) OR
   UPDATE(HEMTEL) OR 
   UPDATE(ARBTEL) OR
   UPDATE(MOBIL) OR
   UPDATE(EPOSTHEM) OR
   UPDATE(ADRSKYDD) OR
   UPDATE(HEMLIGTFN) OR
   UPDATE(CIVKOD) OR
   UPDATE(CIVDAT) OR
   UPDATE(MEDBSKAP) OR
   UPDATE(MEDBDAT) OR
   UPDATE(FODFORS) OR
   UPDATE(FODLAND) OR
   UPDATE(OMRADE) OR
   UPDATE(FOLKFORS) OR
   UPDATE(FOLKLAN) OR
   UPDATE(FOLKKOM) OR
   UPDATE(FOLKDAT) OR
   UPDATE(AVREGORS) OR
   UPDATE(AVREGDAT) OR
   UPDATE(NYCKKOD) OR
   UPDATE(MODMAL) OR
   UPDATE(KOMSPRAK) OR
   UPDATE(KOMSPRAK2) OR 
   UPDATE(KOMSPRAK3) OR 
   UPDATE(INVANDAT) OR 
   UPDATE(TOLKBEHOV) OR 
   UPDATE(MINSIDA) OR
   UPDATE(KADRESS) OR
   UPDATE(KCOADR) OR
   UPDATE(KPOSTNR) OR
   UPDATE(KORT) OR
   UPDATE(KHEMTEL) OR
   UPDATE(KUATDAT) OR
   UPDATE(KFLYKTING) OR
   UPDATE(SMSAVIS) OR
   UPDATE(MAILAVIS) OR
   UPDATE(LCMEDDELANDE) OR
   UPDATE(MINSIDA_VUXNA)
 BEGIN
     DECLARE  
  @PNR          VARCHAR(12),
  @NAMN         VARCHAR(180),
  @ADRESS       VARCHAR(70),
  @COADR       VARCHAR(70),
  @POSTNR       VARCHAR(16),
  @ORT          VARCHAR(64),
  @HEMTEL      VARCHAR(32), 
  @ARBTEL      VARCHAR(32),
  @MOBIL    VARCHAR(32),
  @EPOSTHEM   VARCHAR(100),
  @ADRSKYDD     DECIMAL(1),
  @HEMLIGTFN   DECIMAL(1),
  @CIVKOD    DECIMAL(9),
  @CIVDAT       VARCHAR(8),
  @MEDBSKAP     DECIMAL(9),
  @MEDBDAT      VARCHAR(8),
  @FODFORS      DECIMAL(9),
  @FODLAND      DECIMAL(9),
  @OMRADE      DECIMAL(9),
  @FOLKFORS		DECIMAL(9),
  @FOLKLAN      DECIMAL(9),
  @FOLKKOM      DECIMAL(9),
  @FOLKDAT      VARCHAR(8),
  @AVREGORS     DECIMAL(9),
  @AVREGDAT     VARCHAR(8),
  @NYCKKOD      VARCHAR(24),
  @MODMAL       DECIMAL(9),
  @KOMSPRAK   DECIMAL(9),
  @KOMSPRAK2   DECIMAL(9),
  @KOMSPRAK3   DECIMAL(9),
  @INVANDAT   VARCHAR(8),
  @TOLKBEHOV   DECIMAL(1),
  @MINSIDA    DECIMAL(1),                     
  @KADRESS      VARCHAR(70), 
  @KCOADR      VARCHAR(70), 
  @KPOSTNR       VARCHAR(5),
  @KORT       VARCHAR(27),
  @KHEMTEL      VARCHAR(18),
  @KUATDAT      VARCHAR(8), 
  @KFLYKTING      DECIMAL(1),
  @SMSAVIS		DECIMAL(1),
  @MAILAVIS		DECIMAL(1),
  @LCMEDDELANDE DECIMAL(1),
  @MINSIDA_VUXNA DECIMAL(1),
  @UPDDAT       VARCHAR(8),
  @UPDSIGN      VARCHAR(10),
  
  @NEWPNR          VARCHAR(12),
  @NEWNAMN         VARCHAR(180),
  @NEWADRESS       VARCHAR(70),
  @NEWCOADR       VARCHAR(70),
  @NEWPOSTNR       VARCHAR(16),
  @NEWORT          VARCHAR(64),
  @NEWHEMTEL      VARCHAR(32), 
  @NEWARBTEL      VARCHAR(32),
  @NEWMOBIL    VARCHAR(32),
  @NEWEPOSTHEM   VARCHAR(100),
  @NEWADRSKYDD     DECIMAL(1),
  @NEWHEMLIGTFN   DECIMAL(1),
  @NEWCIVKOD    DECIMAL(9),
  @NEWCIVDAT       VARCHAR(8),
  @NEWMEDBSKAP     DECIMAL(9),
  @NEWMEDBDAT      VARCHAR(8),
  @NEWFODFORS      DECIMAL(9),
  @NEWFODLAND      DECIMAL(9),
  @NEWOMRADE      DECIMAL(9),
  @NEWFOLKFORS		DECIMAL(9),
  @NEWFOLKLAN      DECIMAL(9),
  @NEWFOLKKOM      DECIMAL(9),
  @NEWFOLKDAT      VARCHAR(8),
  @NEWAVREGORS     DECIMAL(9),
  @NEWAVREGDAT     VARCHAR(8),
  @NEWNYCKKOD      VARCHAR(24),
  @NEWMODMAL       DECIMAL(9),
  @NEWKOMSPRAK   DECIMAL(9),
  @NEWKOMSPRAK2   DECIMAL(9),
  @NEWKOMSPRAK3   DECIMAL(9),
  @NEWINVANDAT   VARCHAR(8),
  @NEWTOLKBEHOV   DECIMAL(1),
  @NEWMINSIDA    DECIMAL(1),                     
  @NEWKADRESS      VARCHAR(70), 
  @NEWKCOADR      VARCHAR(70), 
  @NEWKPOSTNR       VARCHAR(5),
  @NEWKORT       VARCHAR(27),
  @NEWKHEMTEL      VARCHAR(18),
  @NEWKUATDAT      VARCHAR(8), 
  @NEWKFLYKTING      DECIMAL(1),
  @NEWSMSAVIS     DECIMAL(1),
  @NEWMAILAVIS      DECIMAL(1),
  @NEWLCMEDDELANDE DECIMAL(1),
  @NEWMINSIDA_VUXNA DECIMAL(1),

  @NEWUPDDAT       VARCHAR(8),
  @NEWUPDSIGN      VARCHAR(10),

  @ANTALRADER    DECIMAL(9)

     SET @ANTALRADER = (SELECT COUNT(*) FROM INSERTED)
     
     DECLARE CURR_UPDPERSON CURSOR FOR 
     SELECT  PNR  ,  NAMN,  ADRESS,  COADR ,  POSTNR,  ORT,  HEMTEL,   ARBTEL,MOBIL,EPOSTHEM,  ADRSKYDD,  HEMLIGTFN
			,  CIVKOD,  CIVDAT,  MEDBSKAP,  MEDBDAT,FODFORS,  FODLAND,  OMRADE,FOLKFORS,FOLKLAN,FOLKKOM,FOLKDAT,AVREGORS,
			AVREGDAT,  NYCKKOD,MODMAL,  KOMSPRAK,  KOMSPRAK2,  KOMSPRAK3,  INVANDAT,  
		  TOLKBEHOV,  MINSIDA  ,  KADRESS,   KCOADR,   KPOSTNR,  KORT,
		  KHEMTEL,  KUATDAT,   KFLYKTING, UPDDAT,UPDSIGN,SMSAVIS,MAILAVIS,LCMEDDELANDE,MINSIDA_VUXNA  FROM DELETED

     OPEN CURR_UPDPERSON
     FETCH NEXT FROM CURR_UPDPERSON INTO  @PNR  ,  @NAMN,  @ADRESS,  @COADR ,  @POSTNR,  @ORT,  @HEMTEL, @ARBTEL,@MOBIL,@EPOSTHEM,  
			@ADRSKYDD,  @HEMLIGTFN	,  @CIVKOD,  @CIVDAT,  @MEDBSKAP,  @MEDBDAT,@FODFORS , @FODLAND,  @OMRADE,@FOLKFORS,@FOLKLAN,
			@FOLKKOM,@FOLKDAT,@AVREGORS,	@AVREGDAT,  @NYCKKOD,@MODMAL,  @KOMSPRAK,  @KOMSPRAK2,  @KOMSPRAK3,  @INVANDAT,  
		  @TOLKBEHOV,  @MINSIDA ,   @KADRESS,   @KCOADR,   @KPOSTNR,  @KORT,
		  @KHEMTEL,  @KUATDAT,   @KFLYKTING,@UPDDAT,@UPDSIGN,@SMSAVIS,@MAILAVIS,@LCMEDDELANDE,@MINSIDA_VUXNA

    WHILE @@FETCH_STATUS = 0
	BEGIN 
     
		DECLARE @SQL VARCHAR(MAX)
		DECLARE @TABLE_OWNER VARCHAR(100)=(SELECT 
            SCH.NAME 
            FROM SYS.SCHEMAS SCH
            JOIN SYS.OBJECTS OBJ
            ON OBJ.schema_id=SCH.schema_id
            WHERE OBJ.NAME='LD0P0A')

		SET @SQL='EXEC '+@TABLE_OWNER+ '.LD0_A01_INSERT' +' '''+ @PNR +''' , '''+ @NAMN
		+ ''' , ''' + @ADRESS+ ''' , ''' + @COADR+ ''' , ''' + @POSTNR+ ''' , ''' + @ORT+ ''' , ''' + @HEMTEL+ ''' , ''' + @ARBTEL+ ''' , ''' + @MOBIL+ ''' , ''' + @EPOSTHEM
		+ ''' , ''' + CAST(@ADRSKYDD AS varchar)+ ''' , ''' + CAST(@HEMLIGTFN AS varchar)+ ''' , ''' + CAST(@CIVKOD AS varchar)+ ''' , ''' + @CIVDAT+ ''' , ''' + CAST(@MEDBSKAP AS varchar)+ ''' , ''' + @MEDBDAT+ ''' , ''' + CAST(@FODFORS AS varchar)
		+ ''' , ''' + CAST(@FODLAND AS varchar)+ ''' , ''' + CAST(@OMRADE AS varchar)+ ''' , ''' + CAST(@FOLKFORS AS varchar)+ ''' , ''' + CAST(@FOLKLAN AS varchar)+ ''' , ''' + CAST(@FOLKKOM AS varchar)+ ''' , ''' + @FOLKDAT+ ''' , ''' + CAST(@AVREGORS AS varchar)
		+ ''' , ''' + @AVREGDAT+ ''' , ''' + @NYCKKOD+ ''' , ''' + CAST(@MODMAL AS varchar)+ ''' , ''' + CAST(@KOMSPRAK AS varchar)+ ''' , ''' + CAST(@KOMSPRAK2 AS varchar)+ ''' , ''' + CAST(@KOMSPRAK3 AS varchar)+ ''' , ''' + @INVANDAT+ ''' , ''' + CAST(@TOLKBEHOV AS varchar)
		+ ''' , ''' + CAST(@MINSIDA AS varchar)+ ''' , ''' + @KADRESS+ ''' , ''' + @KCOADR+ ''' , ''' + @KPOSTNR+ ''' , ''' + @KORT+ ''' , ''' + @KHEMTEL+ ''' , ''' + @KUATDAT+ ''' , ''' + CAST(@KFLYKTING AS varchar)+ ''' , ''' + CAST(@SMSAVIS AS varchar)+ ''' , ''' + CAST(@MAILAVIS AS varchar)
		+ ''' , ''' + CAST(@LCMEDDELANDE AS varchar)+ ''' , ''' + CAST(@MINSIDA_VUXNA AS varchar)
		+ ''' , '''	+ @UPDDAT +''' , '''+ @UPDSIGN +''''
		EXEC (@SQL)

     IF (@ANTALRADER = 1)
       SELECT	  @NEWPNR  = PNR,
				  @NEWNAMN = NAMN,
				  @NEWADRESS = ADRESS,
				  @NEWCOADR = COADR,
				  @NEWPOSTNR=POSTNR,
				  @NEWORT=ORT,
				  @NEWHEMTEL=HEMTEL, 
				  @NEWARBTEL=ARBTEL, 
				  @NEWKADRESS=KADRESS, 
				  @NEWKCOADR=KCOADR, 
				  @NEWKPOSTNR=KPOSTNR,
				  @NEWKORT=KORT,
				  @NEWKHEMTEL=KHEMTEL,
				  @NEWKUATDAT=KUATDAT, 
				  @NEWKFLYKTING=KFLYKTING,
				  @NEWCIVKOD=CIVKOD,
				  @NEWCIVDAT=CIVDAT,
				  @NEWMEDBSKAP=MEDBSKAP,
				  @NEWMEDBDAT=MEDBDAT,
				  @NEWFODFORS=FODFORS,
				  @NEWFODLAND=FODLAND,
				  @NEWOMRADE=OMRADE,
				  @NEWFOLKLAN=FOLKLAN,
				  @NEWFOLKKOM=FOLKKOM,
				  @NEWFOLKDAT=FOLKDAT,
				  @NEWAVREGORS=AVREGORS,
				  @NEWAVREGDAT=AVREGDAT,
				  @NEWADRSKYDD=ADRSKYDD,
				  @NEWHEMLIGTFN=HEMLIGTFN,
				  @NEWNYCKKOD=NYCKKOD,
				  @NEWMOBIL=MOBIL,
				  @NEWEPOSTHEM=EPOSTHEM,
				  @NEWMODMAL=MODMAL,
				  @NEWKOMSPRAK=KOMSPRAK,
				  @NEWKOMSPRAK2=KOMSPRAK2,
				  @NEWKOMSPRAK3=KOMSPRAK3,
				  @NEWINVANDAT=INVANDAT,
				  @NEWTOLKBEHOV=TOLKBEHOV,
				  @NEWMINSIDA=MINSIDA ,
				  @NEWSMSAVIS=SMSAVIS,
				  @NEWMAILAVIS=MAILAVIS,
				  @NEWLCMEDDELANDE=LCMEDDELANDE,
				  @NEWMINSIDA_VUXNA=MINSIDA_VUXNA,
				  @NEWUPDDAT=UPDDAT,
				  @NEWUPDSIGN=UPDSIGN
					FROM INSERTED
     ELSE
       SELECT	  @NEWPNR  = PNR,
				  @NEWNAMN = NAMN,
				  @NEWADRESS = ADRESS,
				  @NEWCOADR = COADR,
				  @NEWPOSTNR=POSTNR,
				  @NEWORT=ORT,
				  @NEWHEMTEL=HEMTEL, 
				  @NEWARBTEL=ARBTEL, 
				  @NEWKADRESS=KADRESS, 
				  @NEWKCOADR=KCOADR, 
				  @NEWKPOSTNR=KPOSTNR,
				  @NEWKORT=KORT,
				  @NEWKHEMTEL=KHEMTEL,
				  @NEWKUATDAT=KUATDAT, 
				  @NEWKFLYKTING=KFLYKTING,
				  @NEWCIVKOD=CIVKOD,
				  @NEWCIVDAT=CIVDAT,
				  @NEWMEDBSKAP=MEDBSKAP,
				  @NEWMEDBDAT=MEDBDAT,
				  @NEWFODFORS=FODFORS,
				  @NEWFODLAND=FODLAND,
				  @NEWOMRADE=OMRADE,
				  @NEWFOLKLAN=FOLKLAN,
				  @NEWFOLKKOM=FOLKKOM,
				  @NEWFOLKDAT=FOLKDAT,
				  @NEWAVREGORS=AVREGORS,
				  @NEWAVREGDAT=AVREGDAT,
				  @NEWADRSKYDD=ADRSKYDD,
				  @NEWHEMLIGTFN=HEMLIGTFN,
				  @NEWNYCKKOD=NYCKKOD,
				  @NEWMOBIL=MOBIL,
				  @NEWEPOSTHEM=EPOSTHEM,
				  @NEWMODMAL=MODMAL,
				  @NEWKOMSPRAK=KOMSPRAK,
				  @NEWKOMSPRAK2=KOMSPRAK2,
				  @NEWKOMSPRAK3=KOMSPRAK3,
				  @NEWINVANDAT=INVANDAT,
				  @NEWTOLKBEHOV=TOLKBEHOV,
				  @NEWMINSIDA=MINSIDA ,
				  @NEWSMSAVIS=SMSAVIS,
				  @NEWMAILAVIS=MAILAVIS,
				  @NEWLCMEDDELANDE=LCMEDDELANDE,
				  @NEWMINSIDA_VUXNA=MINSIDA_VUXNA,
				  @NEWUPDDAT=UPDDAT,
				  @NEWUPDSIGN=UPDSIGN
					FROM INSERTED WHERE	PNR = @PNR

IF (@PNR<>@NEWPNR) 
BEGIN
 IF ((SELECT COUNT(*) FROM LD0P0A01 WHERE PNR = @NEWPNR) > 0)
   DELETE FROM LD0P0A01 WHERE PNR = @NEWPNR

 UPDATE LD0P0A01 SET
 PNR = @NEWPNR
 WHERE PNR=@PNR 

 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWPNR,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Personnr' AND 
 PNR = @NEWPNR
END

IF (@NAMN<>@NEWNAMN) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWNAMN,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Namn' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@ADRESS<>@NEWADRESS) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWADRESS,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Adress' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@COADR<>@NEWCOADR) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWCOADR,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='C/O Adress' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@POSTNR<>@NEWPOSTNR) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWPOSTNR,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Postnr' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@ORT<>@NEWORT) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWORT,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Ort' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@HEMTEL<>@NEWHEMTEL AND @NEWHEMTEL<>' ') 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWHEMTEL,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Hemtelefon' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@ARBTEL<>@NEWARBTEL AND @NEWARBTEL<>' ') 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWARBTEL,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Arbetstelefon' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@MOBIL<>@NEWMOBIL AND @NEWMOBIL<>' ')
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWMOBIL,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Mobil' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@EPOSTHEM<>@NEWEPOSTHEM AND @NEWEPOSTHEM<>' ')
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWEPOSTHEM,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='E-post hem' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@ADRSKYDD<>@NEWADRSKYDD) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWADRSKYDD,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Adresskydd' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@HEMLIGTFN<>@NEWHEMLIGTFN) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWHEMLIGTFN,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Hemligt telefonnummer' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@CIVKOD<>@NEWCIVKOD) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWCIVKOD,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Civilståndskod' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@CIVDAT<>@NEWCIVDAT) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWCIVDAT,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Datum för Civilståndsändring' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@MEDBSKAP<>@NEWMEDBSKAP) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWMEDBSKAP,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Medborgarskap' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@MEDBDAT<>@NEWMEDBDAT) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWMEDBDAT,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Medborgarskap datum' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@FODFORS<>@NEWFODFORS) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWFODFORS,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Födelseförsamling' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@FODLAND<>@NEWFODLAND) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWFODLAND,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Födelseland' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@OMRADE<>@NEWOMRADE) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWOMRADE,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Område' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@FOLKFORS<>@NEWFOLKFORS) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWFOLKFORS,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Församlingstillhörighet' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@FOLKLAN<>@NEWFOLKLAN) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWFOLKLAN,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Län' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@FOLKKOM<>@NEWFOLKKOM) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWFOLKKOM,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Hemkommun' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@FOLKDAT<>@NEWFOLKDAT) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWFOLKDAT,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Folkbokföringsdatum' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@AVREGORS<>@NEWAVREGORS) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWAVREGORS,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Avregistreringsorsak' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@AVREGDAT<>@NEWAVREGDAT) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWAVREGDAT,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Avregistreringsdatum' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@NYCKKOD<>@NEWNYCKKOD) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWNYCKKOD,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Nyckelkod' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@MODMAL<>@NEWMODMAL) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWMODMAL,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Modersmål' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@KOMSPRAK<>@NEWKOMSPRAK) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWKOMSPRAK,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Kommunikationsspråk' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@KOMSPRAK2<>@NEWKOMSPRAK2) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWKOMSPRAK2,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Kommunikationsspråk 2' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@KOMSPRAK3<>@NEWKOMSPRAK3) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWKOMSPRAK3,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Kommunikationsspråk 3' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@INVANDAT<>@NEWINVANDAT) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWINVANDAT,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Invandringsdatum' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@TOLKBEHOV<>@NEWTOLKBEHOV) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWTOLKBEHOV,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Tolkbehov' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@MINSIDA<>@NEWMINSIDA) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWMINSIDA,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Min Sida' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@KADRESS<>@NEWKADRESS) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWKADRESS,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Klientens Adress' AND 
 LD0P0A01.PNR = @NEWPNR
 
IF (@KCOADR<>@NEWKCOADR) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWKCOADR,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Klientens C/O Adress' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@KPOSTNR<>@NEWKPOSTNR) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWKPOSTNR,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Klientens Postnr' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@KORT<>@NEWKORT) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWKORT,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Klientens Ort' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@KHEMTEL<>@NEWKHEMTEL) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWKHEMTEL,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Klientens Hemtelefon' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@KUATDAT<>@NEWKUATDAT) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWKUATDAT,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Klientens Datum för Uppehålls- och arbetstillstånd' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@KFLYKTING<>@NEWKFLYKTING) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWKFLYKTING,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Klienten Flykting' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@SMSAVIS<>@NEWSMSAVIS) 
 UPDATE LD0P0A01 SET
 NEWVALUE=CASE WHEN @NEWSMSAVIS=1 THEN 'Ja' ELSE 'Nej' END,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='SMS Notifiering' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@MAILAVIS<>@NEWMAILAVIS) 
 UPDATE LD0P0A01 SET
 NEWVALUE=CASE WHEN @NEWMAILAVIS=1 THEN 'Ja' ELSE 'Nej' END,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Epost Notifiering' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@LCMEDDELANDE<>@NEWLCMEDDELANDE) 
 UPDATE LD0P0A01 SET
 NEWVALUE=CASE WHEN @NEWLCMEDDELANDE=1 THEN 'Ja' ELSE 'Nej' END,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Lifecare meddelande' AND 
 LD0P0A01.PNR = @NEWPNR

IF (@MINSIDA_VUXNA<>@NEWMINSIDA_VUXNA) 
 UPDATE LD0P0A01 SET
 NEWVALUE=@NEWMINSIDA_VUXNA,
 UPDSIGN=@NEWUPDSIGN,
 UPDDAT=@NEWUPDDAT,
 DATASOURCE = ' '
 WHERE COLNAME='Min Sida Vuxen' AND 
 LD0P0A01.PNR = @NEWPNR

FETCH NEXT FROM CURR_UPDPERSON INTO  @PNR  ,  @NAMN,  @ADRESS,  @COADR ,  @POSTNR,  @ORT,  @HEMTEL, @ARBTEL,@MOBIL,@EPOSTHEM,  
			@ADRSKYDD,  @HEMLIGTFN	,  @CIVKOD,  @CIVDAT,  @MEDBSKAP,  @MEDBDAT,@FODFORS , @FODLAND,  @OMRADE,@FOLKFORS,@FOLKLAN,
			@FOLKKOM,@FOLKDAT,@AVREGORS,	@AVREGDAT,  @NYCKKOD,@MODMAL,  @KOMSPRAK,  @KOMSPRAK2,  @KOMSPRAK3,  @INVANDAT,  
		  @TOLKBEHOV,  @MINSIDA ,   @KADRESS,   @KCOADR,   @KPOSTNR,  @KORT,
		  @KHEMTEL,  @KUATDAT,   @KFLYKTING, @UPDDAT,@UPDSIGN,@SMSAVIS,@MAILAVIS,@LCMEDDELANDE,@MINSIDA_VUXNA
END
CLOSE CURR_UPDPERSON

DEALLOCATE CURR_UPDPERSON

END
GO