One of the common challenges when developing reports for Microsoft Dynamics GP is retrieving Sales Order Processing (SOP) document lines from both work and history tables.
This article provides a complete SQL Server view that combines SOP10200 and SOP30300 into a single data source, making it easier to retrieve sales transaction details for reporting, business intelligence, and data analysis.
The original script was developed for Microsoft Dynamics GP 2018 R2.
Environment:
Microsoft Dynamics GP 2018 R2
Microsoft SQL Server
Sales Order Processing (SOP)
Originally developed: June 30, 2021
Last updated: November 26, 2026
1. Understanding SOP10200 and SOP30300
Microsoft Dynamics GP stores sales transaction line details in separate tables depending on whether the records are in the work or history stage.
| Table |
Description |
Data Source |
SOP10200 |
Sales Transaction Amounts Work |
Work |
SOP30300 |
Sales Transaction Amounts History |
History |
Both tables contain detailed sales transaction information, including item numbers, descriptions, quantities, costs, prices, taxes, shipping information, and inventory-related quantities.
However, their structures are not completely identical. Some columns exist in one table but not in the other.
2. Why Combine Both Tables?
Creating a unified SQL view provides several advantages:
- Retrieve work and historical sales transaction lines from a single source.
- Simplify SQL queries and custom reports.
- Reduce duplicated reporting logic.
- Support Power BI, SQL Server Reporting Services (SSRS), and Crystal Reports.
- Identify the original source table for each record.
- Provide a reusable data source for business intelligence applications.
3. How the SQL View Works
The view uses the SQL Server UNION ALL operator to combine records from both tables.
Unlike a SQL JOIN, which combines related columns horizontally, UNION ALL combines compatible result sets vertically.
SOP10200
Sales Transaction Amounts Work
↓
UNION ALL
↑
Sales Transaction Amounts History
SOP30300
↓
Unified SOP Sales Transaction Lines View
Two additional columns are included to identify the source of each record:
Documents_Status: Unposted or Posted.
Table: SOP10200 or SOP30300.
For compatibility with the original script, columns that do not exist in one of the source tables are represented using zero values or empty strings.
4. Complete SQL View Script
Open SQL Server Management Studio (SSMS) and select the appropriate Dynamics GP company database.
Use CREATE VIEW if the view does not already exist. If you are updating an existing installation of this view, replace CREATE VIEW with ALTER VIEW.
Always review and test custom SQL objects in a test environment before deploying them to a production database.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[Hyou_VW_SOP10200&SOP30300]
AS
-- ==================================================
-- View: Hyou_VW_SOP10200&SOP30300
-- Author: Hussain Ali Al Yousef
-- Created: June 30, 2021
-- Article updated: November 25, 2026
-- Microsoft Dynamics GP 2018 R2
--
-- Description:
-- Combine SOP transaction lines from
-- SOP10200 (Work) and SOP30300 (History).
--
-- Blog:
-- https://hussainalyousef.blogspot.com/
-- ==================================================
SELECT
'Unposted' AS [Documents_Status],
'SOP10200' AS [Table],
SOPTYPE,
SOPNUMBE,
LNITMSEQ,
CMPNTSEQ,
ITEMNMBR,
ITEMDESC,
NONINVEN,
DROPSHIP,
UOFM,
LOCNCODE,
UNITCOST,
ORUNTCST,
UNITPRCE,
ORUNTPRC,
XTNDPRCE,
OXTNDPRC,
REMPRICE,
OREPRICE,
EXTDCOST,
OREXTCST,
MRKDNAMT,
ORMRKDAM,
MRKDNPCT,
MRKDNTYP,
INVINDX,
CSLSINDX,
SLSINDX,
MKDNINDX,
RTNSINDX,
INUSINDX,
INSRINDX,
DMGDINDX,
ITMTSHID,
IVITMTXB,
BKTSLSAM,
ORBKTSLS,
TAXAMNT,
ORTAXAMT,
TXBTXAMT,
OTAXTAMT,
BSIVCTTL,
TRDISAMT,
ORTDISAM,
DISCSALE,
ORDAVSLS,
QUANTITY,
ATYALLOC,
QTYINSVC,
QTYINUSE,
QTYDMGED,
QTYRTRND,
QTYONHND,
QTYCANCE,
QTYCANOT,
QTYONPO,
QTYORDER,
QTYPRBAC,
QTYPRBOO,
QTYPRINV,
QTYPRORD,
QTYPRVRECVD,
QTYRECVD,
QTYREMAI,
QTYREMBO,
QTYTBAOR,
QTYTOINV,
QTYTORDR,
QTYFULFI,
QTYSLCTD,
QTYBSUOM,
EXTQTYAL,
EXTQTYSEL,
ReqShipDate,
FUFILDAT,
ACTLSHIP,
SHIPMTHD,
SALSTERR,
SLPRSNID,
PRCLEVEL,
COMMNTID,
BRKFLD1,
BRKFLD2,
BRKFLD3,
CURRNIDX,
TRXSORCE,
SOPLNERR,
'' AS [DOCNCORR],
ORGSEQNM,
ITEMCODE,
PURCHSTAT,
DECPLQTY,
DECPLCUR,
ODECPLCU,
QTYTOSHP,
XFRSHDOC,
EXCEPTIONALDEMAND,
TAXSCHID,
TXSCHSRC,
PRSTADCD,
ShipToName,
CNTCPRSN,
ADDRESS1,
ADDRESS2,
ADDRESS3,
CITY,
[STATE],
ZIPCODE,
CCode,
COUNTRY,
PHONE1,
PHONE2,
PHONE3,
FAXNUMBR,
Flags,
BackoutTradeDisc,
OrigBackoutTradeDisc,
GPSFOINTEGRATIONID,
INTEGRATIONSOURCE,
INTEGRATIONID,
CONTNBR,
CONTLNSEQNBR,
CONTSTARTDTE,
CONTENDDTE,
CONTITEMNBR,
CONTSERIALNBR,
BULKPICKPRNT,
INDPICKPRNT,
ISLINEINTRA,
SOFULFILLMENTBIN,
MULTIPLEBINS,
Print_Phone_NumberGB,
DEX_ROW_TS,
DEX_ROW_ID
FROM dbo.SOP10200
UNION ALL
SELECT
'Posted' AS [Documents_Status],
'SOP30300' AS [Table],
SOPTYPE,
SOPNUMBE,
LNITMSEQ,
CMPNTSEQ,
ITEMNMBR,
ITEMDESC,
NONINVEN,
DROPSHIP,
UOFM,
LOCNCODE,
UNITCOST,
ORUNTCST,
UNITPRCE,
ORUNTPRC,
XTNDPRCE,
OXTNDPRC,
REMPRICE,
OREPRICE,
EXTDCOST,
OREXTCST,
MRKDNAMT,
ORMRKDAM,
MRKDNPCT,
MRKDNTYP,
INVINDX,
CSLSINDX,
SLSINDX,
MKDNINDX,
RTNSINDX,
INUSINDX,
INSRINDX,
DMGDINDX,
ITMTSHID,
IVITMTXB,
BKTSLSAM,
ORBKTSLS,
TAXAMNT,
ORTAXAMT,
TXBTXAMT,
OTAXTAMT,
BSIVCTTL,
TRDISAMT,
ORTDISAM,
DISCSALE,
ORDAVSLS,
QUANTITY,
ATYALLOC,
QTYINSVC,
QTYINUSE,
QTYDMGED,
QTYRTRND,
QTYONHND,
QTYCANCE,
QTYCANOT,
0.00000 AS [QTYONPO],
QTYORDER,
QTYPRBAC,
QTYPRBOO,
QTYPRINV,
QTYPRORD,
QTYPRVRECVD,
QTYRECVD,
QTYREMAI,
QTYREMBO,
QTYTBAOR,
QTYTOINV,
QTYTORDR,
QTYFULFI,
QTYSLCTD,
QTYBSUOM,
EXTQTYAL,
EXTQTYSEL,
ReqShipDate,
FUFILDAT,
ACTLSHIP,
SHIPMTHD,
SALSTERR,
SLPRSNID,
PRCLEVEL,
COMMNTID,
BRKFLD1,
BRKFLD2,
BRKFLD3,
CURRNIDX,
TRXSORCE,
SOPLNERR,
DOCNCORR,
ORGSEQNM,
ITEMCODE,
PURCHSTAT,
DECPLQTY,
DECPLCUR,
ODECPLCU,
0.00000 AS [QTYTOSHP],
0 AS [XFRSHDOC],
EXCEPTIONALDEMAND,
TAXSCHID,
TXSCHSRC,
PRSTADCD,
ShipToName,
CNTCPRSN,
ADDRESS1,
ADDRESS2,
ADDRESS3,
CITY,
[STATE],
ZIPCODE,
CCode,
COUNTRY,
PHONE1,
PHONE2,
PHONE3,
FAXNUMBR,
Flags,
0.00000 AS [BackoutTradeDisc],
0.00000 AS [OrigBackoutTradeDisc],
'' AS [GPSFOINTEGRATIONID],
0 AS [INTEGRATIONSOURCE],
'' AS [INTEGRATIONID],
CONTNBR,
CONTLNSEQNBR,
CONTSTARTDTE,
CONTENDDTE,
CONTITEMNBR,
CONTSERIALNBR,
0 AS [BULKPICKPRNT],
0 AS [INDPICKPRNT],
0 AS [ISLINEINTRA],
'' AS [SOFULFILLMENTBIN],
0 AS [MULTIPLEBINS],
Print_Phone_NumberGB,
DEX_ROW_TS,
DEX_ROW_ID
FROM dbo.SOP30300;
GO
5. Understanding SOP Document Types
The SOPTYPE column identifies the type of sales transaction in Microsoft Dynamics GP.
| SOPTYPE |
Document Type |
| 1 |
Quote |
| 2 |
Order |
| 3 |
Invoice |
| 4 |
Return |
| 5 |
Back Order |
| 6 |
Fulfillment Order |
6. Practical SQL Query Examples
Example 1: Retrieve sample sales transaction lines
SELECT TOP (100) *
FROM dbo.[Hyou_VW_SOP10200&SOP30300];
Example 2: Retrieve a specific sales invoice
SELECT
Documents_Status,
SOPTYPE,
SOPNUMBE,
ITEMNMBR,
ITEMDESC,
QUANTITY,
UNITPRCE,
XTNDPRCE
FROM dbo.[Hyou_VW_SOP10200&SOP30300]
WHERE SOPNUMBE = 'INV000001'
AND SOPTYPE = 3
ORDER BY
LNITMSEQ,
CMPNTSEQ;
Replace INV000001 with a valid invoice number from your Dynamics GP company database.
Example 3: Retrieve unposted sales orders
SELECT
SOPNUMBE,
ITEMNMBR,
ITEMDESC,
QUANTITY,
ATYALLOC,
QTYREMAI,
LOCNCODE
FROM dbo.[Hyou_VW_SOP10200&SOP30300]
WHERE Documents_Status = 'Unposted'
AND SOPTYPE = 2;
Example 4: Retrieve invoice and return lines for an item
SELECT
Documents_Status,
SOPTYPE,
SOPNUMBE,
ITEMNMBR,
QUANTITY,
UNITCOST,
UNITPRCE,
XTNDPRCE
FROM dbo.[Hyou_VW_SOP10200&SOP30300]
WHERE ITEMNMBR = 'ITEM001'
AND SOPTYPE IN (3, 4);
Replace ITEM001 with the required item number.
Example 5: Count transaction lines by document type
SELECT
Documents_Status,
SOPTYPE,
COUNT_BIG(*) AS LineCount
FROM dbo.[Hyou_VW_SOP10200&SOP30300]
GROUP BY
Documents_Status,
SOPTYPE
ORDER BY
Documents_Status,
SOPTYPE;
This query counts transaction lines rather than unique sales documents. A single SOP document may contain multiple item lines and components.
7. Validate the SQL View
You can compare the number of records in the source tables with the number of records returned by the view.
SELECT
'SOP10200' AS DataSource,
COUNT_BIG(*) AS RowCount
FROM dbo.SOP10200
UNION ALL
SELECT
'SOP30300',
COUNT_BIG(*)
FROM dbo.SOP30300
UNION ALL
SELECT
'Combined View',
COUNT_BIG(*)
FROM dbo.[Hyou_VW_SOP10200&SOP30300];
When the underlying data is not changing during the validation, the combined view should return the sum of the record counts from SOP10200 and SOP30300.
8. Permissions and Security
If Dynamics GP users require access to the custom SQL view, you may optionally grant SELECT permission to the DYNGRP database role.
GRANT SELECT
ON dbo.[Hyou_VW_SOP10200&SOP30300]
TO [DYNGRP];
GO
This step is optional. For external reporting applications, consider granting access only to a dedicated reporting role or authorized database users.
The view exposes potentially sensitive information, including item costs, prices, customer shipping addresses, and contact details. Review access requirements before granting permissions.
9. Important Considerations
Important:
- The original script was developed for Dynamics GP 2018 R2. Verify column availability and data types before using it with other versions.
- The labels Unposted and Posted identify the source tables in this view. They should not be interpreted as independently verified accounting posting statuses.
- Historical SOP documents may include transferred or voided transactions. Additional document header information may be required for accurate financial reporting.
- Zero values and empty strings used for unavailable columns are compatibility placeholders, not necessarily actual transaction values.
- The UNION ALL operator does not remove duplicate records.
- DEX_ROW_ID should not be treated as a globally unique identifier across both source tables.
- Use appropriate filters when querying large company databases.
- Do not use this view alone to calculate total recognized sales revenue without applying the necessary document-type, status, currency, and financial reporting rules.
10. Extending the View for Reporting
This view focuses on sales transaction lines. Additional information can be retrieved from the corresponding SOP document header tables.
| Document Stage |
Header Table |
Line Table |
| Work |
SOP10100 |
SOP10200 |
| History |
SOP30200 |
SOP30300 |
The corresponding header and line tables can be related using both SOPTYPE and SOPNUMBE.
Joining each line source to its corresponding header source enables additional reporting capabilities, including:
- Customer numbers and customer names.
- Document dates and posting dates.
- Document totals and currencies.
- Salesperson and sales territory analysis.
- Document status and void information.
- Sales order fulfillment and historical sales analysis.
11. Frequently Asked Questions
Why use UNION ALL instead of UNION?
UNION ALL preserves all records from both result sets without performing duplicate elimination. This is appropriate when the objective is to combine transaction lines while preserving their original data.
Does this SQL view modify Dynamics GP transaction data?
No. The script creates a database view that retrieves existing records. It does not insert, update, or delete records in the Dynamics GP transaction tables.
Can I use this view with Power BI or SSRS?
Yes. The view can be used as a SQL Server data source for Power BI, SSRS, Crystal Reports, and other reporting applications, subject to the required database permissions.
Does the view work with other Dynamics GP versions?
It may work with other versions, but table structures and available columns should be verified before deployment. The original script targets Dynamics GP 2018 R2.
Conclusion
Combining SOP10200 and SOP30300 into a single SQL Server view provides a practical and reusable approach to accessing Microsoft Dynamics GP sales transaction lines.
By preserving the transaction details and identifying their original source, the view simplifies reporting and provides a foundation for more advanced business intelligence, sales analysis, and ERP reporting solutions.
Related Articles
References
Author: Hussain Ali Al Yousef
Originally published: July 2021
Original script: June 30, 2021
Last updated: November 26, 2026
Category: Microsoft Dynamics GP | SQL Server