for Dynamics GP Lisa Williams and Darrell Moy
Agenda 1. SQL Database Maintenance Plans 2. SQL Jobs Check job status 3. Creating a view for custom SmartList & Reporting 4. Create SQL script using Mail Merge 5. How to make SQL prod back up and restore to test 6. View Batch status and reset stuck batch 7. Back up table before changing contents 8. Copy and Paste Header with Data in SQL Management Studio 9. Find all tables containing column name 10. Truncating the transaction log 11. Some SQL Scripts for data extractions (demo)
IMPORTANT: Commands with UPDATE, DELETE or DROP can ruin your data! Please use these queries with caution. We highly recommend that you backup your database before trying out these commands and to use them first on a test server and/or database. Use at your own risk.
1. SQL Maintenance Plans Database Backups Check Data Integrity Reorganize Index Rebuild Index Update Statistics Cleanup history
2. Check for failed jobs Job types Backups Maintenance Plans Business Alerts SQL Integration services SQL Server Agent Service that runs on server to automate jobs Not available on SQL Express Job Activity Monitor
3. Creating Views Selection of records from SQL table(s) that can be used for various purposes: Custom SmartList Objects Crystal Reports Custom Excel Reports Provides mechanism to join data from multiple tables, create calculated fields, and transform data
4. Mail Merge (MS Word) Mass update, insert of SQL records Data in Excel Query in Word MailMerge to directory Paste results into query window
5. Make a test Company from copy of Production Create test company in GP Set proper security permissions Backup live company in SQL Restore backup of live company in SQL Set the proper file name and location Run SQL script to update test company Refer to Knowledgebase article 871973 See Sample Script
6. Check stuck batch status and resolution Run SQL query to view current activity Select * from DYNAMICS..ACTIVITY Select * from DYNAMICS..SY00800 Select * from DYNAMICS..SY00801 Run SQL query to view status of stuck batch Select BCHSTTUS, MKDTOPST, * from SY00500 Refer to Knowledgebase article 852420 Resolution All users out of GP Update SY00500 Set MKDTOPST=0, BCHSTTUS=0 where BACHNUMB = 'XXX'
7. Back up table before changing contents Copy table structure and data into backup table Use when updating data in live databases Example: using Customer Master table Select * into RM00101_Backup from RM00101
8. Copy and Paste Header with Data in SQL Management Studio SQL Management Studio doesn t copy headers with data by default Useful for copying query results from query grid into Excel Change Setting in Tools Options Query Results SQL Server Results to Grid check the box "Include Column headers when copying or saving the results." http://msdynamicsgp.blogspot.com/2009/10/weekly-dynamic-copy-headings-anddata.html
9. Find all tables containing column name Example using Account Index field SELECT DISTINCT RTRIM(objs.NAME) FROM sys.columns cols INNER JOIN sys.objects objs on (cols.object_id = objs.object_id) INNER JOIN sysindexes indx on (cols.object_id = indx.id) WHERE (cols.name = 'ACTINDX') and (objs.type = 'U') and (indx.rowcnt <> 0)
10. Truncating the transaction log Log files expand and occupy disk space SQL errors in GP when disk if full Run manually or use SQL jobs Use Dynamics BACKUP LOG DYNAMICS with TRUNCATE_ONLY Use Dynamics DBCC SHRINKFILE (2, 10) --2 means log file --10 means the size
Inventory SQL Query Display quantity on hand, allocated and remaining inventory level (IV00102) Demo script: -- LIST SUMMARY COUNTS REGARDLESS OF LOCATION select itemnmbr, qtyonhnd AS MYITEMS_ONHAND, atyalloc AS MYALLOCATEDITEMS, qtyonhnd-atyalloc AS REMAINING_QTYS from iv00102 where rcrdtype=1 order by itemnmbr, locncode -- LIST SUMMARY COUNTS DEPENDING ON LOCATION select itemnmbr, locncode AS LOCATION, qtyonhnd AS MYITEMS_ONHAND, atyalloc AS MYALLOCATEDITEMS, qtyonhnd-atyalloc AS REMAINING_QTYS from iv00102 where rcrdtype=2 order by itemnmbr, locncode
How profitable are each of your customers? Demo script: Script to view how profitable your customer is; declare @Year as varchar(22) set @Year = 2017 select a.custnmbr, c.custname,b.sopnumbe,a.docdate,b.xtndprce Extended_Price, (b.quantity * b.unitcost) Extended_Cost, (b.xtndprce - (b.quantity * b.unitcost)) Profit, round((b.xtndprce - (b.quantity * b.unitcost))/nullif(b.xtndprce,0),0,2) as Gross_Margin from SOP30200 a (NOLOCK), SOP30300 b (NOLOCK), RM00101 c (NOLOCK) where a.sopnumbe=b.sopnumbe and a.soptype=3 and a.custnmbr=c.custnmbr and DATEPART(Year, a.docdate) = @Year order by a.custnmbr,a.sopnumbe
for Dynamics GP Thank You for Attending!