This script is part of the SQL Scripts for Microsoft Dynamics GP where I will be posted the scripts I wrote against Microsoft Dynamics GP over the 19 years before I stopped working with Dynamics GP.
This script was created for a client to run to rename the company database with a prefix and add IF
statement.
/*
Created by Ian Grieve of azurecurve | Ramblings of an IT Professional (http://www.azurecurve.co.uk)
This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int).
*/
DECLARE @CompanyNamePrefix AS VARCHAR(4)
IF @@SERVERNAME = 'SQL-DEV-01\GP' -- dev
SET @CompanyNamePrefix = 'DEV'
IF @@SERVERNAME = 'SQL-TEST-01\GP' -- test
SET @CompanyNamePrefix = 'TEST: '
UPDATE
['Company Master']
SET
CMPNYNAM = LEFT(@CompanyNamePrefix + ': ' + CAST(RTRIM(['Company Master'].CMPNYNAM) + ' ' AS CHAR(150)), 150)
FROM
DYNAMICS..SY01500 AS ['Company Master'] [[Company Master (SY01500)
WHERE
INTERID = DB_NAME()
AND
LEFT(['Company Master'].CMPNYNAM, 3) <> @CompanyNamePrefix
AND
LEFT(['Company Master'].CMPNYNAM, 4) <> @CompanyNamePrefix