Same reply as I put on DynamicsUser:
http://dynamicsuser.net/forums/p/46553/235398.aspx#235398So again, use the CHANGECOMPANY command. What code have you already tried? What errors / problems are you having?
Think about what you want to do step by step or in pseudo-code first
Get the tax registration number for this customer and store it somewhere for future use.
Get the tax registration number for the same customer, but in a different company and store it somewhere for future use.
Compare each of those tax registration numbers and take the appropriate action.
Think about those individually, write the code for each individually, and you will have a solution.