Auerelio Vasquez
asked on
IF THEN Continued
ok, one thing about this, it updates everytime as such...... I just want where it's changed, that's the last bit of this. just need that one more bit of help, to make it work properly.
in other words, only where the OtherReIn info has changed, modifly the lastmodified column....
in other words, only where the OtherReIn info has changed, modifly the lastmodified column....
Need more details. May be sample data or your query would be helpful.
In your UPDATE statement, you can update lastmodifed with GETDATE(). Something like this.
UPDATE your_table
SET OtherReIn = 'something', lastmodifed = GETDATE()
WHERE some_condition
Do you mean something like this?
Declare @updatedid TABLE (AccountID int primary key)
--update
UPDATE MyTable
SET ModifiedDate = CASE WHEN MyTable.OtherReInfo = MyView.OtherReInfo THEN ModifiedDate ELSE GETDATE() END,
OtherReInfo = MyView.OtherReInfo
OUTPUT DELETED.AccountID INTO @updatedid
FROM MyView
WHERE MyTable.AccountID = MyView.AccountID
AND MyTable.OtherReInfo <> MyView.OtherReInfo -- Only when it's different
--insert
INSERT INTO MyTable (AccountID, OtherReInfo, CreatedDate)
SELECT AccountID, OtherReInfo, GETDATE()
FROM MyView
WHERE AccountID NOT IN (SELECT AccountID FROM @updateid)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.