How to rename / drop company from SQL script

herrJonesherrJones Member Posts: 8
edited 2011-12-09 in SQL General
Hello all,

We try to automate the backup/restore procedure for our LIVE-to-TEST procedure.
We are able to backup/restore everything via SSIS.
Now the question remains whether we can automatically:
  • drop a company within the restored database
  • rename a company within the restored database
Can this be done via a SQL-script (or another, automated way)?

Thanks,

Jan

Comments

  • pdjpdj Member Posts: 643
    I think it will be very difficult to do from T-SQL.
    I will suggest to experimenting by doing it in C/AL. Simply rename the Company by code - I guess it will work.
    If it doesn't work to delete a Company record, you simply need to delete all TableData records for the company in the object table. I guess it will work.

    To automate it, you could either user ExpandIT Launch Utillity, or NAV2009 WebServer, or maybe a solution with the NAS. It depends on the enviroment you got.
    Regards
    Peter
  • bbrownbbrown Member Posts: 3,268
    What's wrong with doing it the standard way?
    There are no bugs - only undocumented features.
  • herrJonesherrJones Member Posts: 8
    @pdj: thanx, but that's what I feared for :-k
    I could try it out on one of our development databases. I am not a specialist in C/AL. Just an 'advanced' user...
    Could you please give an example or a good reference where I can start reading?
    The setup is NAV2009 (no rtc) with a NAS. Not sure however how this works exactly.

    @bbrown: I just want to avoid doing the same thing 4 times, when we do a 'live to develop'-restore, deleting companies from the restored 'live' database and renaming the remaining company to a new one. If I could just launch a job...

    Kind regards,

    Jan
  • David_SingletonDavid_Singleton Member Posts: 5,479
    That seems like you do a lot of testing if you need this? Maybe you want to rethink how many changes you are making to your system and how often.
    David Singleton
  • pdjpdj Member Posts: 643
    herrJones wrote:
    I am not a specialist in C/AL. Just an 'advanced' user...
    Then I'll have to suggest, that you contact your NAV partner :wink:

    Any C/AL developer will be able to do it the actual coding in a few minutes, the problem is more to get it automated...

    The code could be something like this: (NOT TESTED AT ALL - NOT EVEN TESTED FOR COMPILATION ERRORS ! USE AT OWN RISK !!!!)

    Global: Company, Record, Company

    // To delete a company...
    Company.GET('Some Company Name');
    Company.DELETE(TRUE);

    // To rename a company...
    Company.GET('Old Company Name');
    Company.RENAME('New Company Name');
    Regards
    Peter
Sign In or Register to comment.