SQL Scripts for Microsoft Dynamics GP: Update Items Default Purchasing Unit of Measure from CSV

Microsoft Dynamics GPThis 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 updates the default purchasing unit of measure on items from a CSV file. It will validate the item during the import and if there are any errors these will be presented to the user and the data will only be updated when there are no errors.

/*
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 TEMP ERROR TABLE */ CREATE TABLE #Errors ( Error VARCHAR(1000) ,ROW_ID INT IDENTITY ) GO /* CREATE TEMP TABLE FOR DATA */ CREATE TABLE #IV00101_IMPORT ( ITEMNMBR VARCHAR(30) ,PRCHSUOM VARCHAR(10) ) GO /* BULK INSERT */ BULK INSERT #IV00101_IMPORT FROM 'c:\temp\ItemPurchasing.txt' WITH (FIELDTERMINATOR = ',' ,ROWTERMINATOR = '\n' ,FIRSTROW = 2 ) GO /* VALIDATE DATA */ INSERT INTO #Errors (Error) --VALUES ( SELECT 'Item record does not exist: ' + CAST(IMPORT.ITEMNMBR AS VARCHAR(100)) FROM #IV00101_IMPORT AS IMPORT LEFT JOIN IV00101 AS ['Item Master'] --Item Master (IV00101) ON ['Item Master'].ITEMNMBR = IMPORT.ITEMNMBR WHERE ['Item Master'].ITEMNMBR IS NULL ) GO /* UPDATE EXISTING DATA IF NO ERRORS */ IF (SELECT COUNT(*) FROM #Errors) = 0 -- UPDATE if Email Details present UPDATE ['Item Master'] SET PRCHSUOM = IMPORT.PRCHSUOM FROM IV00101 AS ['Item Master'] --Item Master (IV00101) INNER JOIN #IV00101_IMPORT AS IMPORT ON IMPORT.ITEMNMBR = ['Item Master'].ITEMNMBR GO /* OUTPUT ERRORS */ IF (SELECT COUNT(*) FROM #Errors) > 0 SELECT Error FROM #Errors ORDER BY ROW_ID GO /* DROP TEMP TABLES */ DROP TABLE #IV00101_IMPORT GO DROP TABLE #Errors GO

Click to show/hide the SQL Scripts for Microsoft Dynamics GP: Update Items Default Purchasing Unit of Measure from CSV Series Index

SQL Scripts for Microsoft Dynamics GP: Update Items Default Purchasing Unit of Measure from CSV

What should we write about next?

If there is a topic which fits the typical ones of this site, which you would like to see me write about, please use the form, below, to submit your idea.

Your Name

Your Email

Suggested Topic

Suggestion Details

Looking for support or consultancy with Microsoft Dynamics GP?

I no longer work with Microsoft Dynamics GP, but the last company I worked for was ISC Software in the UK; if you’re looking for support or consultancy services with Microsoft Dynamics GP you can contact them here.

Leave a Reply

Your email address will not be published. Required fields are marked *