remote sql server update slow

dougfosterNYC
dougfosterNYC used Ask the Experts™
on
I am using a remote sql server 2008 db on a cloud, and I can't run an update sql because it is so slow.  Reading is fast, and I can update a field with a where statement to an id value, but I just want to set the field to zero.  It just hangs running. After 5 minutes I canceled.

Is it something to do with locking?  The table is small, about 18k records, and I don't think anybody else is using it today.

I've tried the sql both from my desktop using Management studio and from a remote desktop session.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Adam MenkesC# ASP.NET Developer
Top Expert 2010

Commented:
Is the field a primary key and / or identity column where 0 would not be allowed?

Author

Commented:
No, it's not primary. I did mention that I have successfully updated a record in that same field using a where statement so I'm only changing one record.
So it seems like it's just being incredibly slow. Is it a locking issue, even if nobody else is hitting the db?
Top Expert 2011

Commented:
can you post the update statement you are attempting?

can you post the table structure/layout?

is the table replicated?
any triggers on the table?
is it a table or a view?
any materialised (indexed) views on the table?

Author

Commented:
It's a table.  super simple.

update mytable set
    NUMBER_OF_HOUSEHOLDS_10 = 0

I don't think there are any triggers in the db.  I don't know about indexed views.  


Adam MenkesC# ASP.NET Developer
Top Expert 2010

Commented:
This will update the whole table as opposed to a single record, so there could be a lock on another record by someone, or perhaps you have a unique index that includes this field.
Adam MenkesC# ASP.NET Developer
Top Expert 2010

Commented:
Or, if it is because it is a remote db, it just appears slower since you are updating 18K records instead of 1. Try adding a WHERE clause (other than the ID=#), just to get that one record and see if the speed is fast.

update mytable set
    NUMBER_OF_HOUSEHOLDS_10 = 0
where lastname='smith' and firstname='john' and dateofbirth='1965-01-15'

Author

Commented:
I had mentioned before that i did use a where clause for one record.  I actually don't know how to test the exact speed, but in Man studio it said 00:00:01.

There is no unique index on this field. And there shouldn't be anybody editing the db today.  It is just a db for staff to edit, and there are only a few people even during business hours.  Today the office is closed.

Can I check for locks, or anything else that might be making it so slow it won't run an update?  I let it run for 10 minutes on 18k records and it was still updating.  
Top Expert 2011

Commented:
it would be better to specify it as
update mytable set
    NUMBER_OF_HOUSEHOLDS_10 = 0
  where number_of_households_10 <> 0

which would at least reduce the amount of logging that was required to take place...

even if the db is simple logged (E.G. LOGGED only to allow rollback of the current transaction)
18K rows being updated will be a significant amount of work.
Top Expert 2011

Commented:
ps when you cancelled you actually give the database more work...

it has to rollback the updates it was attempting, which is often a longer process that the actual update.

so cancelled after 5 minutes , means 5+ minutes to rollback...

are there any database jobs which it regularly schedules to do various scans / tasks, or even a "weekend"
maintenance schedule that you may not be aware of?
Top Expert 2011

Commented:
can you check the database logs to see if there are any identified problems

Author

Commented:
Oh, I hadn't thought of the rollback issue, but that makes sense.

But that doesn't solve my initial problem.  I had, in fact, in my last try used
     where number_of_households_10 > 0

The last one I ran (and canceled, oops), was running for over an hour.  So that just can't be right.  


Author

Commented:
ok, I tried running on a smaller recordset, so I made a filter on one state (Alabama) which is 277 records.  To read it takes 3 seconds.  To update a field takes 20 minutes.

I copied the same table to another db on the same server and ran the same query and it does the entire 18k record table in a second.

So i is indeed something to do with the db and something locking the table. I wish I could track down what it is....
Adam MenkesC# ASP.NET Developer
Top Expert 2010

Commented:
Can you script the slow database and post it here?
See attached.
scriptto.png
Top Expert 2011

Commented:
how did you copy the table?
and how long did the copy take?

what size are the database files on the original database?

Author

Commented:
The copy took a second or two.  

I have a feeling it is the fact that it is set to full recovery.  I believe there is a way to run a transaction that won't get logged.  

In the end, I wrote a looping T-SQL that uses a cursor and steps through each record (see attached code).  It ran the entire 18k db in 8.5 minutes, on 8 fields.  So that is acceptable, although I REALLY prefer not to have to go this way.

I'm concerned I clogged up the log file.

Now I have to update the same fields with values from another table.  This just zeroed them out.  Yikes, there must be an easier way.

declare @mallId nchar(6)
	declare @RowNum int
	declare @showme int
	
	set @showme = 0
	
	declare malllist cursor for  
	select mallcode from mallsysNetT1.dbo._mall
	OPEN malllist
	FETCH NEXT FROM malllist 
	INTO @mallId
	set @RowNum = 0 
	WHILE @@FETCH_STATUS = 0
	BEGIN
	  set @RowNum = @RowNum + 1
	  set @showme = @showme + 1

	  update mallsysNetT1.dbo._mall set 
	NUMBER_OF_HOUSEHOLDS_10 = 0, NUMBER_OF_HOUSEHOLDS_20 = 0, NUMBER_OF_HOUSEHOLDS_5 = 0, 
	AVREGE_HOUSEHOLD_INC_10 = 0, AVREGE_HOUSEHOLD_INC_20 = 0, AVREGE_HOUSEHOLD_INC_5 = 0, 
	MEDIAN_AGE_10 = 0, MEDIAN_AGE_20 = 0, MEDIAN_AGE_5 = 0, 
	POPULATION_10 = 0, POPULATION_20 = 0, POPULATION_5 = 0
	where MALLCODE = @mallId

	  if @showme = 100
		BEGIN
		print 'processed records: ' + cast(@RowNum as char(6)) -- + ' ' + @mallId
		set @showme = 0
		END


	  FETCH NEXT FROM malllist 
	    INTO @mallId
	END
	CLOSE malllist
	DEALLOCATE malllist

Open in new window

Author

Commented:
The log file is now huge, 1.6 gigs.  I don't know what it was before I did the updates.

I'm concerned that I'll double it when I run the next routine to update 7000 records.  

I think looping through each record with a cursor is bad for this.  I still don't know a way to run a fast query that doesn't clog up the log file.
instead of cursur use cross apply

Author

Commented:
Hi jindalankush.

Can you elaborate?  How would I use cross apply and how would hit help?
Top Expert 2011

Commented:
cross apply is just a way of specifying a join

which you should have done to complete the update in one phase, however it will not
make any difference to the speed problems you are already encountering....

can you execute this to confirm if any triggers exist.

sp_helptrigger  @tabname=  'mallsysNetT1.dbo._mall'

Author

Commented:
Here are the results on the trigger.  Is this illuminating?

trigger_name    trigger_owner    isupdate    isdelete    isinsert    isafter    isinsteadof    trigger_schema
_mall_TriggerDeleteChangeLogEntry    dbo    0    1    0    1    0    dbo
_mall_TriggerInsertChangeLogEntry    dbo    0    0    1    1    0    dbo
_mall_TriggerUpdateChangeLogEntry    dbo    1    0    0    1    0    dbo
Top Expert 2011

Commented:
yes so you do have triggers on the table... and that is where your problems lie...

show the code for the

_mall_TriggerUpdateChangeLogEntry

Author

Commented:
Ahh. I think we're onto something.

Here is the trigger code. I actually didn't realize that there can be triggers for just a table.  

What's the hangup and what can I do about it?

Thanks.

Author

Commented:
Oops.  It didn't attach.

USE [mallsysNetT1]
GO
/****** Object:  Trigger [dbo].[_mall_TriggerUpdateChangeLogEntry]    Script Date: 07/05/2010 19:07:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--Auto generated by triggers.exe
--Wednesday, September 27, 2006
ALTER TRIGGER [dbo].[_mall_TriggerUpdateChangeLogEntry] ON [dbo].[_mall] FOR UPDATE AS

DECLARE @CHANGE_USER_ID as smallint
DECLARE @CHANGE_RECORD_ID as int
DECLARE @CHANGE_RECORD_MALLCODE as varchar(6)
DECLARE @CHANGE_FIELD_NAME as varchar(35)
DECLARE @CHANGE_TABLE_NAME as varchar(25)
DECLARE @CHANGE_PREVIOUS_VALUE as varchar(255)
DECLARE @NEW_VALUE as varchar(255)
DECLARE @GUID uniqueidentifier 
DECLARE @CHANGE_TYPE_ID tinyint
SET @CHANGE_TYPE_ID  = 2

SELECT @CHANGE_USER_ID = [USER_ID] FROM _user where [USER_NAME] IS NOT NULL AND [USER_NAME] = (select top 1 [updated_by] from Inserted)

SET @NEW_VALUE = NULL

SET @GUID = NewID()

Select	
@CHANGE_RECORD_MALLCODE = MALLCODE,
@CHANGE_TABLE_NAME = '_mall'
from Inserted in_ 

--MALLNAME
Select @NEW_VALUE = ins.MALLNAME, @CHANGE_FIELD_NAME = 'MALLNAME', @CHANGE_PREVIOUS_VALUE = del.MALLNAME
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--CREATE_DATE
Select @NEW_VALUE = ins.CREATE_DATE, @CHANGE_FIELD_NAME = 'CREATE_DATE', @CHANGE_PREVIOUS_VALUE = del.CREATE_DATE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--MAJOR_UPDATE_DATE
Select @NEW_VALUE = ins.MAJOR_UPDATE_DATE, @CHANGE_FIELD_NAME = 'MAJOR_UPDATE_DATE', @CHANGE_PREVIOUS_VALUE = del.MAJOR_UPDATE_DATE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--MINOR_UPDATE_DATE
Select @NEW_VALUE = ins.MINOR_UPDATE_DATE, @CHANGE_FIELD_NAME = 'MINOR_UPDATE_DATE', @CHANGE_PREVIOUS_VALUE = del.MINOR_UPDATE_DATE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--RENAME_DATE
Select @NEW_VALUE = ins.RENAME_DATE, @CHANGE_FIELD_NAME = 'RENAME_DATE', @CHANGE_PREVIOUS_VALUE = del.RENAME_DATE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--PUBLISH_DATE
Select @NEW_VALUE = ins.PUBLISH_DATE, @CHANGE_FIELD_NAME = 'PUBLISH_DATE', @CHANGE_PREVIOUS_VALUE = del.PUBLISH_DATE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--DEACTIVATE_DATE
Select @NEW_VALUE = ins.DEACTIVATE_DATE, @CHANGE_FIELD_NAME = 'DEACTIVATE_DATE', @CHANGE_PREVIOUS_VALUE = del.DEACTIVATE_DATE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--LAST_UPDATE_FORM_REC_DATE
Select @NEW_VALUE = ins.LAST_UPDATE_FORM_REC_DATE, @CHANGE_FIELD_NAME = 'LAST_UPDATE_FORM_REC_DATE', @CHANGE_PREVIOUS_VALUE = del.LAST_UPDATE_FORM_REC_DATE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--LAST_CONTACT_DATE
Select @NEW_VALUE = ins.LAST_CONTACT_DATE, @CHANGE_FIELD_NAME = 'LAST_CONTACT_DATE', @CHANGE_PREVIOUS_VALUE = del.LAST_CONTACT_DATE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--FOLLOW_UP_DATE
Select @NEW_VALUE = ins.FOLLOW_UP_DATE, @CHANGE_FIELD_NAME = 'FOLLOW_UP_DATE', @CHANGE_PREVIOUS_VALUE = del.FOLLOW_UP_DATE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--HAS_SITEPLAN
Select @NEW_VALUE = ins.HAS_SITEPLAN, @CHANGE_FIELD_NAME = 'HAS_SITEPLAN', @CHANGE_PREVIOUS_VALUE = del.HAS_SITEPLAN
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--SITE_PLAN_ID
Select @NEW_VALUE = ins.SITE_PLAN_ID, @CHANGE_FIELD_NAME = 'SITE_PLAN_ID', @CHANGE_PREVIOUS_VALUE = del.SITE_PLAN_ID
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--SITE_PLAN_DATE
Select @NEW_VALUE = ins.SITE_PLAN_DATE, @CHANGE_FIELD_NAME = 'SITE_PLAN_DATE', @CHANGE_PREVIOUS_VALUE = del.SITE_PLAN_DATE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--SITE_PLAN_DELETE_DATE
Select @NEW_VALUE = ins.SITE_PLAN_DELETE_DATE, @CHANGE_FIELD_NAME = 'SITE_PLAN_DELETE_DATE', @CHANGE_PREVIOUS_VALUE = del.SITE_PLAN_DELETE_DATE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--SITE_PLAN_NOTES
Select @NEW_VALUE = ins.SITE_PLAN_NOTES, @CHANGE_FIELD_NAME = 'SITE_PLAN_NOTES', @CHANGE_PREVIOUS_VALUE = del.SITE_PLAN_NOTES
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--FORMER_NAME
Select @NEW_VALUE = ins.FORMER_NAME, @CHANGE_FIELD_NAME = 'FORMER_NAME', @CHANGE_PREVIOUS_VALUE = del.FORMER_NAME
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--FORMER_OD_NAME
Select @NEW_VALUE = ins.FORMER_OD_NAME, @CHANGE_FIELD_NAME = 'FORMER_OD_NAME', @CHANGE_PREVIOUS_VALUE = del.FORMER_OD_NAME
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--FORMER_LA_NAME
Select @NEW_VALUE = ins.FORMER_LA_NAME, @CHANGE_FIELD_NAME = 'FORMER_LA_NAME', @CHANGE_PREVIOUS_VALUE = del.FORMER_LA_NAME
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--OTHER_SOURCE
Select @NEW_VALUE = ins.OTHER_SOURCE, @CHANGE_FIELD_NAME = 'OTHER_SOURCE', @CHANGE_PREVIOUS_VALUE = del.OTHER_SOURCE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--RESEARCH_NOTES
Select @NEW_VALUE = ins.RESEARCH_NOTES, @CHANGE_FIELD_NAME = 'RESEARCH_NOTES', @CHANGE_PREVIOUS_VALUE = del.RESEARCH_NOTES
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--IS_PUBLISHED
Select @NEW_VALUE = ins.IS_PUBLISHED, @CHANGE_FIELD_NAME = 'IS_PUBLISHED', @CHANGE_PREVIOUS_VALUE = del.IS_PUBLISHED
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--IS_ACTIVE
Select @NEW_VALUE = ins.IS_ACTIVE, @CHANGE_FIELD_NAME = 'IS_ACTIVE', @CHANGE_PREVIOUS_VALUE = del.IS_ACTIVE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--JOINT_VENTURE_PERSON
Select @NEW_VALUE = ins.JOINT_VENTURE_PERSON, @CHANGE_FIELD_NAME = 'JOINT_VENTURE_PERSON', @CHANGE_PREVIOUS_VALUE = del.JOINT_VENTURE_PERSON
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--GEO_CODE_DATE
Select @NEW_VALUE = ins.GEO_CODE_DATE, @CHANGE_FIELD_NAME = 'GEO_CODE_DATE', @CHANGE_PREVIOUS_VALUE = del.GEO_CODE_DATE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--YEAR_MALL_COMPLETED
Select @NEW_VALUE = ins.YEAR_MALL_COMPLETED, @CHANGE_FIELD_NAME = 'YEAR_MALL_COMPLETED', @CHANGE_PREVIOUS_VALUE = del.YEAR_MALL_COMPLETED
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--QUEST_SUBMITTER
Select @NEW_VALUE = ins.QUEST_SUBMITTER, @CHANGE_FIELD_NAME = 'QUEST_SUBMITTER', @CHANGE_PREVIOUS_VALUE = del.QUEST_SUBMITTER
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--GEOCODE_NOTES
Select @NEW_VALUE = ins.GEOCODE_NOTES, @CHANGE_FIELD_NAME = 'GEOCODE_NOTES', @CHANGE_PREVIOUS_VALUE = del.GEOCODE_NOTES
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--EMAIL
Select @NEW_VALUE = ins.EMAIL, @CHANGE_FIELD_NAME = 'EMAIL', @CHANGE_PREVIOUS_VALUE = del.EMAIL
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--WEBSITE
Select @NEW_VALUE = ins.WEBSITE, @CHANGE_FIELD_NAME = 'WEBSITE', @CHANGE_PREVIOUS_VALUE = del.WEBSITE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--ALLOWFAX
Select @NEW_VALUE = ins.ALLOWFAX, @CHANGE_FIELD_NAME = 'ALLOWFAX', @CHANGE_PREVIOUS_VALUE = del.ALLOWFAX
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--ALLOWEMAIL
Select @NEW_VALUE = ins.ALLOWEMAIL, @CHANGE_FIELD_NAME = 'ALLOWEMAIL', @CHANGE_PREVIOUS_VALUE = del.ALLOWEMAIL
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--AUTHORIZATIONFAX
Select @NEW_VALUE = ins.AUTHORIZATIONFAX, @CHANGE_FIELD_NAME = 'AUTHORIZATIONFAX', @CHANGE_PREVIOUS_VALUE = del.AUTHORIZATIONFAX
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--AUTHORIZATIONEMAIL
Select @NEW_VALUE = ins.AUTHORIZATIONEMAIL, @CHANGE_FIELD_NAME = 'AUTHORIZATIONEMAIL', @CHANGE_PREVIOUS_VALUE = del.AUTHORIZATIONEMAIL
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--AUTHORIZATIONDATE
Select @NEW_VALUE = ins.AUTHORIZATIONDATE, @CHANGE_FIELD_NAME = 'AUTHORIZATIONDATE', @CHANGE_PREVIOUS_VALUE = del.AUTHORIZATIONDATE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--UPDATED_BY
Select @NEW_VALUE = ins.UPDATED_BY, @CHANGE_FIELD_NAME = 'UPDATED_BY', @CHANGE_PREVIOUS_VALUE = del.UPDATED_BY
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--MALLPHONE
Select @NEW_VALUE = ins.MALLPHONE, @CHANGE_FIELD_NAME = 'MALLPHONE', @CHANGE_PREVIOUS_VALUE = del.MALLPHONE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--MALLFAX
Select @NEW_VALUE = ins.MALLFAX, @CHANGE_FIELD_NAME = 'MALLFAX', @CHANGE_PREVIOUS_VALUE = del.MALLFAX
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--AUTHORIZATIONNAME
Select @NEW_VALUE = ins.AUTHORIZATIONNAME, @CHANGE_FIELD_NAME = 'AUTHORIZATIONNAME', @CHANGE_PREVIOUS_VALUE = del.AUTHORIZATIONNAME
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--EMAILPDF
Select @NEW_VALUE = ins.EMAILPDF, @CHANGE_FIELD_NAME = 'EMAILPDF', @CHANGE_PREVIOUS_VALUE = del.EMAILPDF
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--PROOF_READ_DATE
Select @NEW_VALUE = ins.PROOF_READ_DATE, @CHANGE_FIELD_NAME = 'PROOF_READ_DATE', @CHANGE_PREVIOUS_VALUE = del.PROOF_READ_DATE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--INTERSECTING_ST
Select @NEW_VALUE = ins.INTERSECTING_ST, @CHANGE_FIELD_NAME = 'INTERSECTING_ST', @CHANGE_PREVIOUS_VALUE = del.INTERSECTING_ST
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--PH_ADDRESS1
Select @NEW_VALUE = ins.PH_ADDRESS1, @CHANGE_FIELD_NAME = 'PH_ADDRESS1', @CHANGE_PREVIOUS_VALUE = del.PH_ADDRESS1
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--PH_ADDRESS2
Select @NEW_VALUE = ins.PH_ADDRESS2, @CHANGE_FIELD_NAME = 'PH_ADDRESS2', @CHANGE_PREVIOUS_VALUE = del.PH_ADDRESS2
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--PH_CITY
Select @NEW_VALUE = ins.PH_CITY, @CHANGE_FIELD_NAME = 'PH_CITY', @CHANGE_PREVIOUS_VALUE = del.PH_CITY
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--PH_STATE_ID
Select @NEW_VALUE = ins.PH_STATE_ID, @CHANGE_FIELD_NAME = 'PH_STATE_ID', @CHANGE_PREVIOUS_VALUE = del.PH_STATE_ID
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--PH_ZIP
Select @NEW_VALUE = ins.PH_ZIP, @CHANGE_FIELD_NAME = 'PH_ZIP', @CHANGE_PREVIOUS_VALUE = del.PH_ZIP
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--PH_COUNTY_ID
Select @NEW_VALUE = ins.PH_COUNTY_ID, @CHANGE_FIELD_NAME = 'PH_COUNTY_ID', @CHANGE_PREVIOUS_VALUE = del.PH_COUNTY_ID
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--PH_COUNTRY_ID
Select @NEW_VALUE = ins.PH_COUNTRY_ID, @CHANGE_FIELD_NAME = 'PH_COUNTRY_ID', @CHANGE_PREVIOUS_VALUE = del.PH_COUNTRY_ID
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--ML_ADDRESS1
Select @NEW_VALUE = ins.ML_ADDRESS1, @CHANGE_FIELD_NAME = 'ML_ADDRESS1', @CHANGE_PREVIOUS_VALUE = del.ML_ADDRESS1
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--ML_ADDRESS2
Select @NEW_VALUE = ins.ML_ADDRESS2, @CHANGE_FIELD_NAME = 'ML_ADDRESS2', @CHANGE_PREVIOUS_VALUE = del.ML_ADDRESS2
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--ML_CITY
Select @NEW_VALUE = ins.ML_CITY, @CHANGE_FIELD_NAME = 'ML_CITY', @CHANGE_PREVIOUS_VALUE = del.ML_CITY
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--ML_STATE_ID
Select @NEW_VALUE = ins.ML_STATE_ID, @CHANGE_FIELD_NAME = 'ML_STATE_ID', @CHANGE_PREVIOUS_VALUE = del.ML_STATE_ID
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--ML_ZIP
Select @NEW_VALUE = ins.ML_ZIP, @CHANGE_FIELD_NAME = 'ML_ZIP', @CHANGE_PREVIOUS_VALUE = del.ML_ZIP
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--ML_COUNTY_ID
Select @NEW_VALUE = ins.ML_COUNTY_ID, @CHANGE_FIELD_NAME = 'ML_COUNTY_ID', @CHANGE_PREVIOUS_VALUE = del.ML_COUNTY_ID
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--ML_COUNTRY_ID
Select @NEW_VALUE = ins.ML_COUNTRY_ID, @CHANGE_FIELD_NAME = 'ML_COUNTRY_ID', @CHANGE_PREVIOUS_VALUE = del.ML_COUNTRY_ID
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--GC_ADDRESS1
Select @NEW_VALUE = ins.GC_ADDRESS1, @CHANGE_FIELD_NAME = 'GC_ADDRESS1', @CHANGE_PREVIOUS_VALUE = del.GC_ADDRESS1
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--GC_ADDRESS2
Select @NEW_VALUE = ins.GC_ADDRESS2, @CHANGE_FIELD_NAME = 'GC_ADDRESS2', @CHANGE_PREVIOUS_VALUE = del.GC_ADDRESS2
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--GC_CITY
Select @NEW_VALUE = ins.GC_CITY, @CHANGE_FIELD_NAME = 'GC_CITY', @CHANGE_PREVIOUS_VALUE = del.GC_CITY
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--GC_STATE_ID
Select @NEW_VALUE = ins.GC_STATE_ID, @CHANGE_FIELD_NAME = 'GC_STATE_ID', @CHANGE_PREVIOUS_VALUE = del.GC_STATE_ID
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--GC_ZIP
Select @NEW_VALUE = ins.GC_ZIP, @CHANGE_FIELD_NAME = 'GC_ZIP', @CHANGE_PREVIOUS_VALUE = del.GC_ZIP
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--GC_COUNTY_ID
Select @NEW_VALUE = ins.GC_COUNTY_ID, @CHANGE_FIELD_NAME = 'GC_COUNTY_ID', @CHANGE_PREVIOUS_VALUE = del.GC_COUNTY_ID
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--GC_COUNTRY_ID
Select @NEW_VALUE = ins.GC_COUNTRY_ID, @CHANGE_FIELD_NAME = 'GC_COUNTRY_ID', @CHANGE_PREVIOUS_VALUE = del.GC_COUNTRY_ID
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--CENTER_CLASS_ID
Select @NEW_VALUE = ins.CENTER_CLASS_ID, @CHANGE_FIELD_NAME = 'CENTER_CLASS_ID', @CHANGE_PREVIOUS_VALUE = del.CENTER_CLASS_ID
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--GLA
Select @NEW_VALUE = ins.GLA, @CHANGE_FIELD_NAME = 'GLA', @CHANGE_PREVIOUS_VALUE = del.GLA
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--SITESIZE
Select @NEW_VALUE = ins.SITESIZE, @CHANGE_FIELD_NAME = 'SITESIZE', @CHANGE_PREVIOUS_VALUE = del.SITESIZE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--LEVELS
Select @NEW_VALUE = ins.LEVELS, @CHANGE_FIELD_NAME = 'LEVELS', @CHANGE_PREVIOUS_VALUE = del.LEVELS
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--SHAPE_ID
Select @NEW_VALUE = ins.SHAPE_ID, @CHANGE_FIELD_NAME = 'SHAPE_ID', @CHANGE_PREVIOUS_VALUE = del.SHAPE_ID
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--HAS_FOOD_COURT
Select @NEW_VALUE = ins.HAS_FOOD_COURT, @CHANGE_FIELD_NAME = 'HAS_FOOD_COURT', @CHANGE_PREVIOUS_VALUE = del.HAS_FOOD_COURT
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--FOOD_COURT_SEATS
Select @NEW_VALUE = ins.FOOD_COURT_SEATS, @CHANGE_FIELD_NAME = 'FOOD_COURT_SEATS', @CHANGE_PREVIOUS_VALUE = del.FOOD_COURT_SEATS
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--TOTAL_STORES
Select @NEW_VALUE = ins.TOTAL_STORES, @CHANGE_FIELD_NAME = 'TOTAL_STORES', @CHANGE_PREVIOUS_VALUE = del.TOTAL_STORES
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--LAST_RENOVATION
Select @NEW_VALUE = ins.LAST_RENOVATION, @CHANGE_FIELD_NAME = 'LAST_RENOVATION', @CHANGE_PREVIOUS_VALUE = del.LAST_RENOVATION
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--EXPANSION_PLANNED
Select @NEW_VALUE = ins.EXPANSION_PLANNED, @CHANGE_FIELD_NAME = 'EXPANSION_PLANNED', @CHANGE_PREVIOUS_VALUE = del.EXPANSION_PLANNED
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--WHEN_EXPAND
Select @NEW_VALUE = ins.WHEN_EXPAND, @CHANGE_FIELD_NAME = 'WHEN_EXPAND', @CHANGE_PREVIOUS_VALUE = del.WHEN_EXPAND
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--DESIGN_TYPE_ID
Select @NEW_VALUE = ins.DESIGN_TYPE_ID, @CHANGE_FIELD_NAME = 'DESIGN_TYPE_ID', @CHANGE_PREVIOUS_VALUE = del.DESIGN_TYPE_ID
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--YEAR_OPENED
Select @NEW_VALUE = ins.YEAR_OPENED, @CHANGE_FIELD_NAME = 'YEAR_OPENED', @CHANGE_PREVIOUS_VALUE = del.YEAR_OPENED
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--COMMENT
Select @NEW_VALUE = ins.COMMENT, @CHANGE_FIELD_NAME = 'COMMENT', @CHANGE_PREVIOUS_VALUE = del.COMMENT
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--IS_SPACE_AVAILABLE
Select @NEW_VALUE = ins.IS_SPACE_AVAILABLE, @CHANGE_FIELD_NAME = 'IS_SPACE_AVAILABLE', @CHANGE_PREVIOUS_VALUE = del.IS_SPACE_AVAILABLE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--TYPES_OF_TENANT_SOUGHT
Select @NEW_VALUE = ins.TYPES_OF_TENANT_SOUGHT, @CHANGE_FIELD_NAME = 'TYPES_OF_TENANT_SOUGHT', @CHANGE_PREVIOUS_VALUE = del.TYPES_OF_TENANT_SOUGHT
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--HAS_OUTPARCELS
Select @NEW_VALUE = ins.HAS_OUTPARCELS, @CHANGE_FIELD_NAME = 'HAS_OUTPARCELS', @CHANGE_PREVIOUS_VALUE = del.HAS_OUTPARCELS
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--OUTPARCELS_SPACE_AVAILABLE
Select @NEW_VALUE = ins.OUTPARCELS_SPACE_AVAILABLE, @CHANGE_FIELD_NAME = 'OUTPARCELS_SPACE_AVAILABLE', @CHANGE_PREVIOUS_VALUE = del.OUTPARCELS_SPACE_AVAILABLE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--ACCEPTS_TEMP_TENANTS
Select @NEW_VALUE = ins.ACCEPTS_TEMP_TENANTS, @CHANGE_FIELD_NAME = 'ACCEPTS_TEMP_TENANTS', @CHANGE_PREVIOUS_VALUE = del.ACCEPTS_TEMP_TENANTS
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--HAS_CART_KIOSK
Select @NEW_VALUE = ins.HAS_CART_KIOSK, @CHANGE_FIELD_NAME = 'HAS_CART_KIOSK', @CHANGE_PREVIOUS_VALUE = del.HAS_CART_KIOSK
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--HAS_TEMP_IN_LINE_SPACE
Select @NEW_VALUE = ins.HAS_TEMP_IN_LINE_SPACE, @CHANGE_FIELD_NAME = 'HAS_TEMP_IN_LINE_SPACE', @CHANGE_PREVIOUS_VALUE = del.HAS_TEMP_IN_LINE_SPACE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--MSA_ID
Select @NEW_VALUE = ins.MSA_ID, @CHANGE_FIELD_NAME = 'MSA_ID', @CHANGE_PREVIOUS_VALUE = del.MSA_ID
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--NEAR_MAJOR_CITY
Select @NEW_VALUE = ins.NEAR_MAJOR_CITY, @CHANGE_FIELD_NAME = 'NEAR_MAJOR_CITY', @CHANGE_PREVIOUS_VALUE = del.NEAR_MAJOR_CITY
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--DISTANCE_TO_NEAR_MAJOR_CITY
Select @NEW_VALUE = ins.DISTANCE_TO_NEAR_MAJOR_CITY, @CHANGE_FIELD_NAME = 'DISTANCE_TO_NEAR_MAJOR_CITY', @CHANGE_PREVIOUS_VALUE = del.DISTANCE_TO_NEAR_MAJOR_CITY
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--POPULATION_OF_PRIMARY_MARKET
Select @NEW_VALUE = ins.POPULATION_OF_PRIMARY_MARKET, @CHANGE_FIELD_NAME = 'POPULATION_OF_PRIMARY_MARKET', @CHANGE_PREVIOUS_VALUE = del.POPULATION_OF_PRIMARY_MARKET
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--DISTANCE_OF_PRIMARY_MARKET
Select @NEW_VALUE = ins.DISTANCE_OF_PRIMARY_MARKET, @CHANGE_FIELD_NAME = 'DISTANCE_OF_PRIMARY_MARKET', @CHANGE_PREVIOUS_VALUE = del.DISTANCE_OF_PRIMARY_MARKET
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--AVG_HOUSEHOLD_INCOME
Select @NEW_VALUE = ins.AVG_HOUSEHOLD_INCOME, @CHANGE_FIELD_NAME = 'AVG_HOUSEHOLD_INCOME', @CHANGE_PREVIOUS_VALUE = del.AVG_HOUSEHOLD_INCOME
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--TOTAL_SALES
Select @NEW_VALUE = ins.TOTAL_SALES, @CHANGE_FIELD_NAME = 'TOTAL_SALES', @CHANGE_PREVIOUS_VALUE = del.TOTAL_SALES
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--SALES_PER_SQFT
Select @NEW_VALUE = ins.SALES_PER_SQFT, @CHANGE_FIELD_NAME = 'SALES_PER_SQFT', @CHANGE_PREVIOUS_VALUE = del.SALES_PER_SQFT
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--NEAREST_COMPETING_MALL
Select @NEW_VALUE = ins.NEAREST_COMPETING_MALL, @CHANGE_FIELD_NAME = 'NEAREST_COMPETING_MALL', @CHANGE_PREVIOUS_VALUE = del.NEAREST_COMPETING_MALL
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--DISTANCE_TO_NEAR_COMP_MALL
Select @NEW_VALUE = ins.DISTANCE_TO_NEAR_COMP_MALL, @CHANGE_FIELD_NAME = 'DISTANCE_TO_NEAR_COMP_MALL', @CHANGE_PREVIOUS_VALUE = del.DISTANCE_TO_NEAR_COMP_MALL
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--TRAFFIC_COUNTS_WEEKLY
Select @NEW_VALUE = ins.TRAFFIC_COUNTS_WEEKLY, @CHANGE_FIELD_NAME = 'TRAFFIC_COUNTS_WEEKLY', @CHANGE_PREVIOUS_VALUE = del.TRAFFIC_COUNTS_WEEKLY
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--TRAFFIC_COUNTS_MONTHLY
Select @NEW_VALUE = ins.TRAFFIC_COUNTS_MONTHLY, @CHANGE_FIELD_NAME = 'TRAFFIC_COUNTS_MONTHLY', @CHANGE_PREVIOUS_VALUE = del.TRAFFIC_COUNTS_MONTHLY
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--TRAFFIC_COUNTS_ANNUALLY
Select @NEW_VALUE = ins.TRAFFIC_COUNTS_ANNUALLY, @CHANGE_FIELD_NAME = 'TRAFFIC_COUNTS_ANNUALLY', @CHANGE_PREVIOUS_VALUE = del.TRAFFIC_COUNTS_ANNUALLY
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--NUMBER_OF_HOUSEHOLDS_5
Select @NEW_VALUE = ins.NUMBER_OF_HOUSEHOLDS_5, @CHANGE_FIELD_NAME = 'NUMBER_OF_HOUSEHOLDS_5', @CHANGE_PREVIOUS_VALUE = del.NUMBER_OF_HOUSEHOLDS_5
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--NUMBER_OF_HOUSEHOLDS_10
Select @NEW_VALUE = ins.NUMBER_OF_HOUSEHOLDS_10, @CHANGE_FIELD_NAME = 'NUMBER_OF_HOUSEHOLDS_10', @CHANGE_PREVIOUS_VALUE = del.NUMBER_OF_HOUSEHOLDS_10
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--NUMBER_OF_HOUSEHOLDS_20
Select @NEW_VALUE = ins.NUMBER_OF_HOUSEHOLDS_20, @CHANGE_FIELD_NAME = 'NUMBER_OF_HOUSEHOLDS_20', @CHANGE_PREVIOUS_VALUE = del.NUMBER_OF_HOUSEHOLDS_20
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--AVREGE_HOUSEHOLD_INC_5
Select @NEW_VALUE = ins.AVREGE_HOUSEHOLD_INC_5, @CHANGE_FIELD_NAME = 'AVREGE_HOUSEHOLD_INC_5', @CHANGE_PREVIOUS_VALUE = del.AVREGE_HOUSEHOLD_INC_5
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--AVREGE_HOUSEHOLD_INC_10
Select @NEW_VALUE = ins.AVREGE_HOUSEHOLD_INC_10, @CHANGE_FIELD_NAME = 'AVREGE_HOUSEHOLD_INC_10', @CHANGE_PREVIOUS_VALUE = del.AVREGE_HOUSEHOLD_INC_10
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--AVREGE_HOUSEHOLD_INC_20
Select @NEW_VALUE = ins.AVREGE_HOUSEHOLD_INC_20, @CHANGE_FIELD_NAME = 'AVREGE_HOUSEHOLD_INC_20', @CHANGE_PREVIOUS_VALUE = del.AVREGE_HOUSEHOLD_INC_20
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--POPULATION_5
Select @NEW_VALUE = ins.POPULATION_5, @CHANGE_FIELD_NAME = 'POPULATION_5', @CHANGE_PREVIOUS_VALUE = del.POPULATION_5
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--POPULATION_10
Select @NEW_VALUE = ins.POPULATION_10, @CHANGE_FIELD_NAME = 'POPULATION_10', @CHANGE_PREVIOUS_VALUE = del.POPULATION_10
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--POPULATION_20
Select @NEW_VALUE = ins.POPULATION_20, @CHANGE_FIELD_NAME = 'POPULATION_20', @CHANGE_PREVIOUS_VALUE = del.POPULATION_20
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--MEDIAN_AGE_5
Select @NEW_VALUE = ins.MEDIAN_AGE_5, @CHANGE_FIELD_NAME = 'MEDIAN_AGE_5', @CHANGE_PREVIOUS_VALUE = del.MEDIAN_AGE_5
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--MEDIAN_AGE_10
Select @NEW_VALUE = ins.MEDIAN_AGE_10, @CHANGE_FIELD_NAME = 'MEDIAN_AGE_10', @CHANGE_PREVIOUS_VALUE = del.MEDIAN_AGE_10
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--MEDIAN_AGE_20
Select @NEW_VALUE = ins.MEDIAN_AGE_20, @CHANGE_FIELD_NAME = 'MEDIAN_AGE_20', @CHANGE_PREVIOUS_VALUE = del.MEDIAN_AGE_20
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--DEC_LAT
Select @NEW_VALUE = ins.DEC_LAT, @CHANGE_FIELD_NAME = 'DEC_LAT', @CHANGE_PREVIOUS_VALUE = del.DEC_LAT
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--DEC_LON
Select @NEW_VALUE = ins.DEC_LON, @CHANGE_FIELD_NAME = 'DEC_LON', @CHANGE_PREVIOUS_VALUE = del.DEC_LON
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--NUMBER_OF_PARK_SPACES
Select @NEW_VALUE = ins.NUMBER_OF_PARK_SPACES, @CHANGE_FIELD_NAME = 'NUMBER_OF_PARK_SPACES', @CHANGE_PREVIOUS_VALUE = del.NUMBER_OF_PARK_SPACES
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--IS_JOINT_VENTURE
Select @NEW_VALUE = ins.IS_JOINT_VENTURE, @CHANGE_FIELD_NAME = 'IS_JOINT_VENTURE', @CHANGE_PREVIOUS_VALUE = del.IS_JOINT_VENTURE
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--DMA_ID
Select @NEW_VALUE = ins.DMA_ID, @CHANGE_FIELD_NAME = 'DMA_ID', @CHANGE_PREVIOUS_VALUE = del.DMA_ID
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

--IS_DEMO
Select @NEW_VALUE = ins.IS_DEMO, @CHANGE_FIELD_NAME = 'IS_DEMO', @CHANGE_PREVIOUS_VALUE = del.IS_DEMO
from Inserted ins, Deleted del
IF(@NEW_VALUE <> @CHANGE_PREVIOUS_VALUE or (@NEW_VALUE is NULL AND @CHANGE_PREVIOUS_VALUE is NOT NULL) or (@NEW_VALUE is NOT NULL AND @CHANGE_PREVIOUS_VALUE is NULL) )
BEGIN

Insert into _changeLog (
CHANGE_USER_ID,
CHANGE_RECORD_MALLCODE,
CHANGE_FIELD_NAME,
CHANGE_TABLE_NAME,
CHANGE_PREVIOUS_VALUE, 
CHANGE_TYPE_ID, 
CHANGE_GUID )
values(
@CHANGE_USER_ID,
@CHANGE_RECORD_MALLCODE,
@CHANGE_FIELD_NAME,
@CHANGE_TABLE_NAME,
@CHANGE_PREVIOUS_VALUE, 
@CHANGE_TYPE_ID, 
@GUID
)
END

Open in new window

Top Expert 2011
Commented:
OK THATS ONE OF THE worst triggers i've ever seen

its totally screwed...

its basic problem is that it doesn't cater for multiple operations ie your update "multiple rows"

its just selecting a random row from the update and logging it , it may not even be consistent
in the the old and new values it has selected may not belong to the same row...

the cause of the poor performance is the cartesian product join between the inserted and deleted tables..

18000 * 18000 = 324million rows  which its doing for each column on the table...

reason there are no joining conditions on the statement.

even when its catering for your single row update, its incredibly inefficient...

those 1000's of lines of code and multiple statements should just be written as a single insert
statement with a proper join between inserted and deleted joined to a table of the column names
(information_schema.columns) which with a case statement would manage all the updates...


given that it says it was auto generated presumably the other triggers have similar problems, as well as any others its been used for.


You have a serious problem, and probably need to consider the audit implications, of this error across the business.


From another perspective, the trigger should obviously be disallowing your update because you are not following proper process for the update .ie not providing proper AUDIT CONTROL information.


Author

Commented:
Yea, well, this db is tied to a .NET editing app that we inherited.  The client is still using the editing app since it is functional, and is very complex (full of lots of forms).  

So, we complete redid the website (www.shoppingcenters.com) that is based on this data, which is now php/mysql.  The data in the ms sql is ported over once a month with a script.  

So we will continue with the legacy system for a while, but need to learn all about it, for better or worse.

I had to update some data on the backend so I was circumventing the .NET app.  

Thank you so much (lowfatspread).  I'd love any last comments you have.  I don't quite understand what you mean by not providing the propert AUDIT CONTROL information, but I assume that is because I am bypassing the app and updating the table through sql.  

You've been very helpful.

Thanks again.

Doug

Author

Commented:
Very knowledgeable....

Author

Commented:
I forget to ask, in the end, if I did something BAD by writing a cursor-based sp and loop through the records.  And if there is anything that can be done with the trigger to disable it for an update query if we happen to be outside the app.

Obviously I'm concerned about screwing something up.....
Top Expert 2011

Commented:
you can disable triggers , but thats never really advisable unless you have taken the database down for maintenance and excluded all user .system access.

other mechanisms can be built into triggers to allow them to be disabled for "ad-hoc" maintenance purposes , but i didn't see any provision for that in the update one...

its a fundamental design decision/principle that needs thought at the start of system
design.

>> if I did something BAD by writing a cursor-based sp
That depends on the nature of your contact with the client...
The handover of the system should have specified the approved maintenance procedures to be used for ad-hoc maintenance... Given the way the trigger is written
i can only assume that only single row updates are envisioned....
The cursor is ok for ad-hoc processing , although i think i'd have generated actual
inidvidual update statement and run them in batches of say 1000 to reduce log overhead.
(The audit requirements of userid etc need to be thought through).


however the methodology behind the updates must have been communicated, to your company, and by the sound of it the client is still using the database as the master for system information.  

As i said you need to sit down and discuss the audit implications of what you've just done! . On a related point since 4 years isn't a long time for a system , i   wonder if the new system hasn't been introduced because of poor performance due to these triggers, which could probably be easily tackled.    
Something like this should generate the SQl that the UPDATE trigger should be executing.. 


declare @where varchar(max),@Ins varchar(max),@sql varchar(max),@prev

Select @where=coalesce(@where+' Or ','Where ')+'(I.['+column_name+']<>d.['+column_name
               +'] or not (i.['+column_name+'] is null and d.['+column_name+'] is null))'
               +char(10)
       @ins=coalesce(@ins+' ',' case column_name ')+'When '''+column_name+''' Then '
            +case when datatype not like '%char' then 'convert(varchar(255),' else '' end
            +'i.['+column_name+']'
            +case when datatype not like '%char' then ')' else '' end
            +char(10)
       @prev=coalesce(@prev+' ',' case column_name ')+'when '''+column_name+''' Then '
            +case when datatype not like '%char' then 'convert(varchar(255),' else '' end
            +'d.['+column_name+']'
            +case when datatype not like '%char' then ')' else '' end
            +char(10)
from information_schema.columns
where table_schema='dbo'
and table_name='_mall'
and column_name<>'Mallcode'
order by ordinal_position

Set @sql='Insert into _changelog (change_user_id,change_record_mallcode'
        +',change_field_name,change_table_name,change_previous_value,change_type_id'
        +',change_guid)'+char(10)
        +' select i.updated_by,i.mallcode,column_name,''_mall'''+char(10)
        +@prev+' end '+char(10)
        +',2,@GUID'   
        +' From Inserted as I Inner Join Deleted as D on I.Mallcode=d.mallcode '+char(10)
        +' (select column_name from Indormation_schema.columns where table_schema=''dbo'''+char(10)
        +' and table_name=''_mall'' and column_name<>''mallcode'' order by ordinal_position) as c '+char(10)
        +@where+char(10)
  
Print @sql 

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial