sql server 2008 - Invalid Object Name for Table which is successfully updated in the same Stored Procedure -


we seeing 'interesting behavior our sql sever database. have merge statement selects table x. in match clauses there subselect table x. when execute stored procedure sql server tools works fine. when executed ipc (an etl tool) exception invalid object name 'x'.

so far nothing special understand there can lots of things wrong permissions , stuff.

the strange thing: merge statement in try block , in catch block error message gets written table x via update statement! how possible when sql server complains can't find table x?

also works fine stored procedure constructed in same way (via code generation) on different set of tables.

the code looks this

    merge ...     using     (select ...     dbo.x     ...     when not matched target      , not exists (select 1 dbo.x q2 ...)     insert (...     )     values (...     )     when matched , q.action='d'     delete     when matched , not exists (select 1 dbo.x q3 ...)     update      set       ...      output $action @l_summaryofchanges;     -- query results of table variable.     select action, count(*) countperchange     @l_summaryofchanges     group action;   end try   begin catch     update dbo.x     set last_error_msg=error_message(), error_counter=error_counter+1     sync_id=@l_syncid   end catch 

any ideas going on?invalid object name 'sync$_tabteiledaten'.

we found it. gbn's question triggered realization usage of x had nothing exception. in fact on target table of merge trigger referencing x different schema without specifying schema.

may benefit way debugged shit:

  • we duplicated x new name (y) , still got error message saying 'invalid object name 'x'. @ point thought might reference view or ..
  • we removed columns (there lots of) merge statement, except necessary due not null constraints. problem persisted
  • we removed 1 of branches of merge statement @ time. problem persisted.
  • we removed complete merge statement. error gone. @ point realized fishy might go on target table.
  • on inspection found trigger hell.

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -