There is a lot of ways to accomplish this but you can't avoid making the column value to parameter value comparison.However, you could have sql do the comparison for you by way of a union statement. ie:set nocount ondeclare @addressbase table (id int ,address1 varchar(20) ,address2 varchar(20) ,suburb varchar(20) ,city varchar(20))insert @addressbase (id, address1, address2, suburb, city)select 1 ,'123' ,'someroad' ,'sqlteam estates' ,'unionville'-------------------------------------------------------------input parametersdeclare @address1 varchar(20) ,@address2 varchar(20) ,@suburb varchar(20) ,@city varchar(20)select @address1 = '987' ,@address2 = 'someroad' ,@suburb = 'sqlteam estates' ,@city = 'unionville'--table variable to hold either 1 or 2 rows (depending on whether values match or not)declare @tb table (rowid int identity(1,1) ,id int ,address1 varchar(20) ,address2 varchar(20) ,suburb varchar(20) ,city varchar(20))--Only the distinct values will be selected from this union'd statement--so if everything matches then only one row will be inserted into @tbinsert @tb (id, address1, address2, suburb, city)select id, address1, address2, suburb, city from @addressbasewhere id=1union --allselect 1, @address1, @address2, @suburb, @city --insert historyTable (id, address1, address2, suburb, city)select id, address1, address2, suburb, cityfrom @tbwhere rowid > 1
EDIT:although this is a heck of a lot easier:select id, address1, address2, suburb, city from @addressbasewhere id=1and (address1 <> @address1 or address2 <> @address2 or suburb <> @suburb or city <> @city)
Be One with the OptimizerTG