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 to allow a client to rename sites in Dynamics GP from a CSV file.
If the name provided was only DO NOT USE then this was added to the start of the existing site description (which was then truncated to the maximum length of 30 characters) otherwise the site description was replaced with the one from the file.
/*
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).
*/
CREATE TABLE #Sites
(
LOCNCODE VARCHAR(10)
,LOCNDESC VARCHAR(30)
)
GO
BULK INSERT
#Sites
FROM
'C:\Temp\Site Descriptions.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
UPDATE
IV
SET
IV.LOCNDSCR = (
CASE WHEN Sites.LOCNDESC = 'DO NOT USE' THEN
LEFT(RTRIM(Sites.LOCNDESC) + ' - ' + RTRIM(IV.LOCNDSCR),30)
ELSE
RTRIM(Sites.LOCNDESC)
END
)
FROM
IV40700 IV
INNER JOIN
#Sites As Sites
ON
Sites.LOCNCODE = IV.LOCNCODE
GO
DROP TABLE #Sites
GO