What I have always done is to have the program just pass all data to the
stored proc and do the update.
Then for logging changes, I do something like this (well, I have tools to
generate it):
I have a changeLog tables that I use to monitor all columns that I am
concerned with. The parent table is:
changeLog(changeActionType, tableName, identityValue, date, userName)
changeLogItem (changeLogId, fieldName, Value)
Note that I only concern myself with past values, so you only need this for
DELETE and UPDATE, since you have the current values. It is messy, but
quite efficient. It is easily automatable with a little bit of coding in
VB, or I use ERwin macros in my model.
--This is the insert of the header record, that tells us which record was
touched
insert into changeLog(changeActionTypeID, tableName, identityValue, date,
userName)
select 'UPDATE', 'tableName', <integer key of the table>, getdate(),
suser_sname()
from deleted
--and for each column we want to log
insert into changeLogItem (changeLogId, fieldName, Value)
select changeLog.changeLogId, 'column1',
convert(varchar(2000),deleted.column1)
from deleted
join inserted
on inserted.primaryKey = deleted.primaryKey
join changeLog
on changeLog.identityValue = inserted.<integer key of the
table>
and date = @logDate
where inserted.column1 <> deleted.column1
or (inserted.column1 is null and deleted.column1 is not null)
or (inserted.column1 is not null and deleted.column1 is null)
UNION ALL
select changeLog.changeLogId, 'column2',
convert(varchar(2000),deleted.column2)
from deleted
join inserted
on inserted.primaryKey = deleted.primaryKey
join changeLog
on changeLog.identityValue = inserted.<integer key of the
table>
and date = @logDate
where inserted.column2 <> deleted.column2
or (inserted.column2 is null and deleted.column2 is not null)
or (inserted.column2 is not null and deleted.column2 is null)
--
----------------------------------------------------------------------------
Louis Davidson -
dr***@hotmail.com
SQL Server MVP
Compass Technology Management -
www.compass.net
Pro SQL Server 2000 Database Design -
http://www.apress.com/book/bookDisplay.html?bID=266
Blog -
http://spaces.msn.com/members/drsql/
Note: Please reply to the newsgroups only unless you are interested in
consulting services. All other replies may be ignored :)
"Roy" <ro**********@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
Thanks for the tip Dave! I didn't even know the command "coalesce"
existed!
But doesn't this bring up the original point? Since I still need a
series of IF's to determine if the data has changed and modify it
accordingly, would it be more effective to just send all the info to
the SP and have it do all the crunching and setting to NULL?