Rename an AX company on SQL

February 24, 2010 at 22:57
filed under Dynamics AX
Tagged ,

A while ago, I talked about deleting an AX company on SQL, but of course, you can also use the sp_MSforeachtable stored procedure to rename a company (= change the DataAreaId of a company).

In the next example, I rename CEE to CEA:

EXEC sp_MSforeachtable 'update ? set DataAreaID = "CEA" where ?.DataAreaID = "CEE"'

UPDATE DataArea SET ID = 'CEA' WHERE DataArea.ID = 'CEE'
UPDATE CompanyDomainList SET CompanyID = 'CEA' WHERE CompanyID = 'CEE'

5 comments

RSS / trackback

  1. Severin

    Does it work for Dynamics AX 2012 R2?

    kind regards,
    Severin

  2. Klaas Deforche

    Hi Severin,

    I don’t know, I never tested this with R2 (I don’t have R2 installed at the moment either).
    Just try it out on a backup :).

  3. Vaibhav

    Hi Severin,
    Did you tried it with Dynamics AX 2012 R2?
    Regards
    Vaibhav

  4. Petr Janik

    Hi,

    I think it works neither for AX2012 nor AX2009. For example, the table SpecTrans has two fields (SpecCompany, RefCompany) with DataAreaId of company.

    Regards
    Petr Janik

  5. Klaas Deforche

    Hi Petr,

    Thank you for your comment.
    That’s correct, tables that contain a refcompany field will not be converted correctly.
    Either way, I wouldn’t really recommend using this method other that in your dev environment with little data for example.
    My intention is more to demonstrate the use of the EXEC sp_MSforeachtable procedure.

respond