DROP TRIGGER LD0T0A01_UPD_HIS4
;
CREATE TRIGGER LD0T0A01_UPD_HIS4 ON LD0P0A01
FOR UPDATE
AS
IF UPDATE(NEWVALUE)
BEGIN
DECLARE @PNR VARCHAR(12)=(SELECT PNR FROM INSERTED)

DECLARE @OLDVALUE VARCHAR(180)
DECLARE @OLDVALUE1 VARCHAR(180)
DECLARE @UPDDAT1 VARCHAR(180)
DECLARE @UPDDAT2 VARCHAR(180)
DECLARE @UPDSIGN1 VARCHAR(180)
DECLARE @UPDSIGN2 VARCHAR(180)

DECLARE @OLD_MEDDAT VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Medborgarskap datum')
DECLARE @NEWVALUE_MEDDAT VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Medborgarskap datum')

DECLARE @OLD_MINSIDA VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Min sida Ek.bistånd')
DECLARE @NEWVALUE_MINSIDA VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Min sida Ek.bistånd')

DECLARE @OLD_MOBIL VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Mobil')
DECLARE @NEWVALUE_MOBIL VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Mobil')

DECLARE @OLD_MODMAL VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Modersmål')
DECLARE @NEWVALUE_MODMAL VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Modersmål')

DECLARE @OLD_NAMN VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Namn')
DECLARE @NEWVALUE_NAMN VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Namn')

DECLARE @OLD_NYKOD VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Nyckelkod')
DECLARE @NEWVALUE_NYKOD VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Nyckelkod')

DECLARE @OLD_OMRADE VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Område')
DECLARE @NEWVALUE_OMRADE VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Område')

DECLARE @OLD_ORT VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Ort')
DECLARE @NEWVALUE_ORT VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Ort')

IF @NEWVALUE_MEDDAT<>@OLD_MEDDAT
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Medborgarskap datum')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Medborgarskap datum')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Medborgarskap datum')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Medborgarskap datum')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Medborgarskap datum')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Medborgarskap datum')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_MEDDAT,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Medborgarskap datum'
END

IF @NEWVALUE_MINSIDA<>@OLD_MINSIDA
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Min sida Ek.bistånd')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Min sida Ek.bistånd')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Min sida Ek.bistånd')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Min sida Ek.bistånd')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Min sida Ek.bistånd')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Min sida Ek.bistånd')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_MINSIDA,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Min sida Ek.bistånd'
END

IF @NEWVALUE_MOBIL<>@OLD_MOBIL
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Mobil')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Mobil')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Mobil')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Mobil')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Mobil')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Mobil')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_MOBIL,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Mobil'
END

IF @NEWVALUE_MODMAL<>@OLD_MODMAL
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Modersmål')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Modersmål')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Modersmål')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Modersmål')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Modersmål')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Modersmål')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_MODMAL,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Modersmål'
END

IF @NEWVALUE_NAMN<>@OLD_NAMN
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Namn')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Namn')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Namn')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Namn')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Namn')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Namn')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_NAMN,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Namn'
END

IF @NEWVALUE_NYKOD<>@OLD_NYKOD
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Nyckelkod')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Nyckelkod')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Nyckelkod')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Nyckelkod')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Nyckelkod')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Nyckelkod')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_NYKOD,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Nyckelkod'
END

IF @NEWVALUE_OMRADE<>@OLD_OMRADE
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Område')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Område')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Område')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Område')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Område')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Område')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_OMRADE,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Område'
END

IF @NEWVALUE_ORT<>@OLD_ORT
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Ort')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Ort')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Ort')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Ort')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Ort')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Ort')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_ORT,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Ort'
END
END
;
DROP TRIGGER LD0T0A01_UPD_HIS5
;
CREATE TRIGGER LD0T0A01_UPD_HIS5 ON LD0P0A01
FOR UPDATE
AS
IF UPDATE(NEWVALUE)
BEGIN
DECLARE @PNR VARCHAR(12)=(SELECT PNR FROM INSERTED)

DECLARE @OLDVALUE VARCHAR(180)
DECLARE @OLDVALUE1 VARCHAR(180)
DECLARE @UPDDAT1 VARCHAR(180)
DECLARE @UPDDAT2 VARCHAR(180)
DECLARE @UPDSIGN1 VARCHAR(180)
DECLARE @UPDSIGN2 VARCHAR(180)

DECLARE @OLD_PNR VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Personnr')
DECLARE @NEWVALUE_PNR VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Personnr')

DECLARE @OLD_POSTNR VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Postnr')
DECLARE @NEWVALUE_POSTNR VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Postnr')

DECLARE @OLD_TOLK VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Tolkbehov')
DECLARE @NEWVALUE_TOLK VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Tolkbehov')

DECLARE @OLD_UPDDAT VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Uppdateringsdatum')
DECLARE @NEWVALUE_UPDDAT VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringsdatum')

DECLARE @OLD_UPDDATK VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Uppdateringsdatum för Klient')
DECLARE @NEWVALUE_UPDDATK VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringsdatum för Klient')

DECLARE @OLD_UPDSIGN VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Uppdateringssignatur')
DECLARE @NEWVALUE_UPDSIGN VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringssignatur')

DECLARE @OLD_UPDSIGNK VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Uppdateringssignatur för Klient')
DECLARE @NEWVALUE_UPDSIGNK VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringssignatur för Klient')

DECLARE @OLD_SMSAVIS VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='SMS Notifiering')
DECLARE @NEWVALUE_SMSAVIS VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='SMS Notifiering')

DECLARE @OLD_MAILAVIS VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Epost Notifiering')
DECLARE @NEWVALUE_MAILAVIS VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Epost Notifiering')

DECLARE @OLD_LCMEDDELANDE VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Meddelande')
DECLARE @NEWVALUE_LCMEDDELANDE VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Meddelande')

DECLARE @OLD_MINSIDA_VUXEN VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Min Sida Vuxen')
DECLARE @NEWVALUE_MINSIDA_VUXEN VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Min Sida Vuxen')

IF @NEWVALUE_PNR<>@OLD_PNR
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Personnr')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Personnr')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Personnr')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Personnr')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Personnr')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Personnr')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_PNR,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Personnr'
END

IF @NEWVALUE_POSTNR<>@OLD_POSTNR
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Postnr')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Postnr')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Postnr')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Postnr')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Postnr')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Postnr')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_POSTNR,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Postnr'
END

IF @NEWVALUE_TOLK<>@OLD_TOLK
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Tolkbehov')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Tolkbehov')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Tolkbehov')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Tolkbehov')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Tolkbehov')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Tolkbehov')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_TOLK,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Tolkbehov'
END

IF @NEWVALUE_UPDDAT<>@OLD_UPDDAT
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringsdatum')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringsdatum')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringsdatum')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringsdatum')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringsdatum')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringsdatum')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_UPDDAT,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Uppdateringsdatum'
END

IF @NEWVALUE_UPDDATK<>@OLD_UPDDATK
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringsdatum för Klient')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringsdatum för Klient')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringsdatum för Klient')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringsdatum för Klient')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringsdatum för Klient')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringsdatum för Klient')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_UPDDATK,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Uppdateringsdatum för Klient'
END

IF @NEWVALUE_UPDSIGN<>@OLD_UPDSIGN
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringssignatur')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringssignatur')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringssignatur')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringssignatur')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringssignatur')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringssignatur')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_UPDSIGN,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Uppdateringssignatur'
END

IF @NEWVALUE_UPDSIGNK<>@OLD_UPDSIGNK
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringssignatur för Klient')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringssignatur för Klient')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringssignatur för Klient')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringssignatur för Klient')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringssignatur för Klient')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Uppdateringssignatur för Klient')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_UPDSIGNK,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Uppdateringssignatur för Klient'
END

IF @NEWVALUE_SMSAVIS<>@OLD_SMSAVIS
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='SMS Notifiering')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='SMS Notifiering')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='SMS Notifiering')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='SMS Notifiering')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='SMS Notifiering')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='SMS Notifiering')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_SMSAVIS,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='SMS Notifiering'
END

IF @NEWVALUE_MAILAVIS<>@OLD_MAILAVIS
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Epost Notifiering')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Epost Notifiering')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Epost Notifiering')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Epost Notifiering')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Epost Notifiering')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Epost Notifiering')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_MAILAVIS,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Epost Notifiering'
END

IF @NEWVALUE_LCMEDDELANDE<>@OLD_LCMEDDELANDE
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Meddelande')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Meddelande')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Meddelande')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Meddelande')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Meddelande')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Meddelande')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_LCMEDDELANDE,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Meddelande'
END

IF @NEWVALUE_MINSIDA_VUXEN<>@OLD_MINSIDA_VUXEN
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Min Sida Vuxen')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Min Sida Vuxen')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Min Sida Vuxen')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Min Sida Vuxen')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Min Sida Vuxen')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Min Sida Vuxen')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_MINSIDA_VUXEN,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Min Sida Vuxen'
END
END
;
