4/24/2019
1
Querying Dynamics GP Data Using SQL ServerApril 25, 2019
TO RECEIVE CPE CREDIT
• Participate in entire webinar
• Answer attendance checks & polls when they are provided
• If you are viewing this webinar in a group, complete group attendance form o All group attendance forms must be submitted to [email protected] within 24
hours of live webinar
o Answer polling questions when they are provided
• If all eligibility requirements are met, each participant will be emailed their CPE certificate within 15 business days of live webinar
4/24/2019
2
INTRODUCTIONS
Charles Allen Senior Managing Consultant• More than 27 years of experience • Microsoft MVP
AGENDA• How to Determine Tables for Reports &
Queries
• Resources for Finding Tables
• SQL Objects
• Querying GP Data
• Q&A
4/24/2019
3
SQL Objects
SQL Objects
• Tables
• Views
• Stored Procedures
• Functions
4/24/2019
4
Tables
• The lowest level storage of data
• Each module comes with many tables
• Windows utilize multiple tables
• Tables utilize keys to quickly find records
Tables
CUSTNMBR CUSTNAME CUSTCLAS CNTCPRSN STMTNAME
AARONFIT0001 Aaron Fitz Electrical
USA-ILMO-T1 Aaron Fitz Electrical
ADAMPARK0001 Adam Park Resort USA-INMI-T2 Adam Park ResortADVANCED0001 Advanced Paper
Co.USA-ILMO-T1 Advanced Paper
Co.ADVANCED0002 Advanced Tech
Satellite SystemCAN-ONMBSK-T6 Advanced Tech
Satellite System
Select * From RM00101
4/24/2019
5
Views
• SQL views are a combination of one or more tables
• They select specific columns
• They select specific rows
• Security can be set at the view level instead of the table level
• Can provide simpler ways of viewing data
SQL Views
CustomerNumber
Customer Name Address 1 Address 2 City
AARONFIT0001 Aaron Fitz Electrical
One Microsoft Way
Redmond
ADAMPARK0001 Adam Park Resort Suite 9876 321 Chestnut Drive
Indianapolis
ADVANCED0001 Advanced Paper Co.
456 19th Street S. Chicago
ADVANCED0001 Advanced Tech Satellite System
8765 66 Ave. Toronto
Select * From Customers
4/24/2019
6
Stored Procedures
• A group of one or more Transact-SQL statements
• Returns data like a table or view
• Can accept parameters
• Security can be set on the stored procedure instead of tables
• Used to manipulate data
• Used for reports like Aged Trial Balance
Stored ProceduresUSE AdventureWorks2012; GO CREATE PROCEDURE HumanResources.uspGetEmployeesTest2 @LastName nvarchar(50), @FirstName nvarchar(50) AS SET NOCOUNT ON; SELECT FirstName, LastName, Department FROM HumanResources.vEmployeeDepartmentHistory WHERE FirstName = @FirstName AND LastName = @LastName AND EndDate IS NULL; GO
4/24/2019
7
Functions
• Table-Valued – Returns a table data type
• Scalar • Returns a single value • Good for converting numeric values to spelled out information• Example: DYN_FUNC_Gender – Gets spelled out gender instead of number
o 1 = Male
o 2 = Female
Functions
/****** Object: UserDefinedFunction [dbo].[DYN_FUNC_Gender] Script Date: 4/9/2019 12:29:04 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
create function [dbo].[DYN_FUNC_Gender] (@iIntEnum integer) returns varchar(100) as begin declare @oVarcharValuestring varchar(100) set @oVarcharValuestring = case when @iIntEnum = 1 then 'Male' when @iIntEnum = 2 then 'Female' when @iIntEnum = 3 then 'N/A' else '' end RETURN(@oVarcharValuestring) END
GO
4/24/2019
8
SQL Objects
How to Determine Tables for Reports &Queries
4/24/2019
9
How to Determine Tables
• GP Table Schema
• Dictionaries
• Series
Table Types
Main Table Type Physical Name Abbreviation Technical Name Abbreviation
Master 000 – 099 MSTRWork 100 – 199 WORKOpen 200 – 299 OPENHistory 300 – 399 HISTSetup 400 – 499 SETPTemp 500 – 599 TEMPRelation 600 – 699 RELReport Options 700 – 799 ROPT
4/24/2019
10
Table Names
• Display – Name that is easiest to understand, like RM Customer MSTR
• Physical – Name used for the physical table, like RM00101
• Technical – Name used in Report Writer & in Alert Messages, like RM_CUST_MSTR
How to Understand a Physical Table Name
Sample abbreviations for module GL – General Ledger CM – Bank ReconciliationRM – Receivables Management PM – Payables ManagementPOP – Purchase Order Processing SOP – Sales Order ProcessingINV – Invoicing IV – Inventory UPR – US Payroll PA – Project AccountingBOM – Bill of Materials AAG – Analytical AccountingMOP – MFG Order Processing BE – HR Benefits
4/24/2019
11
How to Understand a Physical Table Name
• Table numbers
• Examples• RM00101 – Customer Master• PM20000 – PM Transaction OPEN File• GL30000 – Account Transaction History
Resources for Finding Data
4/24/2019
12
Resources for Finding Data
• Resource Descriptions
• Dynamics SDK
• GP Table Reference
• Query for Finding Tables with Column
• Existing Reports
Resource Descriptions
TablesDisplays lists of
tables by product & module
FieldsDisplays fields &
tables using them
WindowsDisplays
windows & tables used
4/24/2019
13
Resource Descriptions
Dynamics SDK
• Installed from the GP media
• Provides a collection of documents for table information
• Provides a list of functions & procedures
4/24/2019
14
GP Table Reference
• Website that provides tables by module http://dyndeveloper.com/DynModule.aspx
• Easy to use
• Can be searched by Table Name & Field Name
Query for Finding Tables with a Column
SELECT SYSOBJECTS.NAME FROM SYSCOLUMNS,SYSOBJECTS WHERE SYSCOLUMNS.NAME = 'CUSTNMBR' AND SYSCOLUMNS.ID = SYSOBJECTS.ID and SYSOBJECTS.TYPE = 'U' ORDER BY SYSOBJECTS.NAME
Provides a list of tables containing a specific column name
4/24/2019
15
Existing Reports
• GP Report Writer
• SSRS Report Builder
• Dynamics GP Integration Guide –Provides information about SmartLists
Using GP Reports
4/24/2019
16
Querying GP Data
Querying GP Data
• SELECT
• UPDATE
• INSERT
4/24/2019
17
Select Statement
• SELECT CUSTNMBR, SLSAMNT
• FROM RM20101
• WHERE DOCDATE BETWEEN ‘2017-04-01’ AND ‘2017-04-30’ AND RMDTYPAL = 1
• GROUP BY CUSTNMBR
• HAVING SUM(SLSAMNT) > 1000
• ORDER BY CUSTNMBR
Update Statement
• UPDATE RM00101
• SET SHIPMTHD = ‘GROUND’
• WHERE SALSTERR = ‘TERRITORY 1’
4/24/2019
18
Insert Statement
• INSERT INTO SY04100
• (BANKID, BANKNAME, ADDRESS1, ADDRESS2, ADDRESS3, CITY, STATE, ZIPCODE, COUNTRY, PHNUMBR1, PHNUMBR2, PHONE3, FAXNUMBR, TRNSTNBR, BNKBRNCH, NOTEINDX, DDTRANUM)
• FROM
• VALUES
• (‘BBVA’, ‘BBVA BANK’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘044000808’, ‘’, 326, ‘044000808’)
Querying GP Data
4/24/2019
19
RESOURCES
• System Administrator’s Guide
• Microsoft Docs (https://docs.Microsoft.com/en-us/)
• Microsoft Dynamics GP Integration Guide
4/24/2019
20
BKDTECHNOLOGIES SUPPORT CENTER
• BKD Technologies Support Center for Microsoft Dynamics GP o 877.253.7778 (toll free)o [email protected] Monday–Friday, 8 a.m.–5 p.m.
BKD, LLP is registered with the National Association of State Boards of Accountancy (NASBA) as a sponsor of continuing professional education on the National Registry of CPE Sponsors. State boards of accountancy have final authority on the acceptance of individual courses for CPE credit. Complaints regarding registered sponsors may be submitted to the National Registry of CPE Sponsors through its website: www.nasbaregistry.org.
The information contained in these slides is presented by professionals for your information only & is not to be considered as legal advice. Applying specific information to your situation requires careful consideration of facts & circumstances. Consult your BKD advisor or legal counsel before acting on any matters covered.
4/24/2019
21
CPE CREDIT
• CPE credit may be awarded upon verification of participant attendance
• For questions, concerns or comments regarding CPE credit, please email the BKD Learning & Development Department at [email protected]
Thank You!Charles Allen, Senior Managing Consultant
713.499.4629 | [email protected]