We do not have your tables and data, so it’s difficult for us to debug any problems, but the following compiles and runs:
create table contacts (client_id_copy int,custid int,client_id int) create table profile(custid int,client_id int,custtype varchar(10)) DECLARE @changes TABLE (client_id_copy INT, client_id INT); UPDATE contacts SET client_id_copy=a.client_id OUTPUT deleted.client_id_copy,inserted.client_id into @changes FROM profile a, contacts b WHERE a.custid=b.custid and NOT(Client_ID_copy > '') and b.custid in (select custid from profile where custtype='EZ2'); select * from @changes
As I said, I don’t know if this is right, because we don’t know what your tables look like (I just made some definitions). Each column specified in the OUTPUT section must contain the corresponding table name or alias (either inserted or deleted ):
<column_name> ::= { DELETED | INSERTED | from_table_name } . { * | column_name } | $action
Please note that { DELETED | INSERTED | from_table_name } { DELETED | INSERTED | from_table_name } { DELETED | INSERTED | from_table_name } not marked as optional, therefore OUTPUT client_id_copy, does not work.
source share