DROP TRIGGER LD0T0A01_UPD_HIS5
GO
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')

DECLARE @OLD_SKYDDADFOLKBOKF VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Skyddad folkbokföring')
DECLARE @NEWVALUE_SKYDDADFOLKBOKF VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Skyddad folkbokföring')

DECLARE @OLD_MINSIDA_ARBETSMARKNAD VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Min Sida Arbetsmarknad')
DECLARE @NEWVALUE_MINSIDA_ARBETSMARKNAD VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Min Sida Arbetsmarknad')

DECLARE @OLD_YRKE VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Yrke')
DECLARE @NEWVALUE_YRKE VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Yrke')

DECLARE @OLD_PRIMART_SPRAK VARCHAR(180)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Primärt Språk')
DECLARE @NEWVALUE_PRIMART_SPRAK VARCHAR(180)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Primärt Språk')

DECLARE @OLD_TESTPERSON DECIMAL(1)=(SELECT NEWVALUE FROM INSERTED WHERE PNR=@PNR AND COLNAME='Testperson')
DECLARE @NEWVALUE_TESTPERSON DECIMAL(1)=(SELECT NEWVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Testperson')

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

IF @NEWVALUE_SKYDDADFOLKBOKF<>@OLD_SKYDDADFOLKBOKF
BEGIN

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

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_SKYDDADFOLKBOKF,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Skyddad folkbokföring'
END

IF @NEWVALUE_MINSIDA_ARBETSMARKNAD<>@OLD_MINSIDA_ARBETSMARKNAD
BEGIN

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

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

IF @NEWVALUE_YRKE<>@OLD_YRKE
BEGIN

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

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

IF @NEWVALUE_PRIMART_SPRAK<>@OLD_PRIMART_SPRAK
BEGIN

	SET @OLDVALUE=(SELECT OLDVALUE FROM DELETED WHERE PNR=@PNR AND COLNAME='Primärt Språk')
	SET @OLDVALUE1=(SELECT OLDVALUE1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Primärt Språk')
	SET @UPDDAT1=(SELECT UPDDAT FROM DELETED WHERE PNR=@PNR AND COLNAME='Primärt Språk')
	SET @UPDDAT2=(SELECT UPDDAT1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Primärt Språk')
	SET @UPDSIGN1=(SELECT UPDSIGN FROM DELETED WHERE PNR=@PNR AND COLNAME='Primärt Språk')
	SET @UPDSIGN2=(SELECT UPDSIGN1 FROM DELETED WHERE PNR=@PNR AND COLNAME='Primärt Språk')

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_PRIMART_SPRAK,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Primärt Språk'
END

IF @NEWVALUE_TESTPERSON<>@OLD_TESTPERSON
BEGIN

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

	UPDATE LD0P0A01 SET OLDVALUE=@NEWVALUE_TESTPERSON,OLDVALUE1=@OLDVALUE,OLDVALUE2=@OLDVALUE1,UPDDAT1=@UPDDAT1,UPDSIGN1=@UPDSIGN1,UPDDAT2=@UPDDAT2,UPDSIGN2=@UPDSIGN2
		WHERE PNR=@PNR
		AND COLNAME='Testperson'
END
END
GO