Tip: The SQL Webstore Examples can be downloaded in a zip here. For Microsoft RMS, a special kit can be downloaded here.
QuickBooks
This example requires that QuickBooks be accessible via ODBC. A popular tool for this is QODBC. The read-only version of QODBC is included with QuickBooks Enterprise Edition, and can be downloaded here. To post shipping details back to QuickBooks requires the read-write version of QODBC.
The 'get' Query:
SELECTi.RefNumber as RecordID,i.ShipAddressAddr1 as ContactName,i.ShipAddressAddr2 as CompanyName,i.ShipAddressAddr3 as Address1,i.ShipAddressCity as City,i.ShipAddressState as State,i.ShipAddressPostalCode as ZIP,i.ShipAddressCountry as Country,c.Phone as Phone,c.Email as Email,i.RefNumber as ReferenceFROM Invoice iLEFT OUTER JOIN Customer c ON c.ListID = i.CustomerRefListIDWHEREi.RefNumber = '%SEARCHPARAM%'
To save the shipment to the QuickBooks sales order.
Note: For this example SQL to work, there must be two custom fields added to the Invoice/Sales Order: TrackNo and ShipCharges.
UPDATE INVOICESETCustomFieldShipCharges = '%SHIPPINGCHARGES%',CustomFieldTrackNo = '%TRACKINGNUMBER%'WHERERefNumber = '%RecordID%'
Northwind Example Database: SQL Server
'Get' Data Query:
SELECTo.OrderID as RecordID,o.ShipName as ContactName,c.CompanyName as CompanyName,o.ShipAddress as Address1,o.ShipCity as City,o.ShipRegion as State,o.ShipPostalCode as ZIP,o.ShipCountry as Country,c.Phone as PhoneFROM dbo.orders oLEFT OUTER JOIN dbo.Customers c ON c.CustomerID = o.CustomerIDWHERE o.OrderID LIKE '%SEARCHPARAM%%'
History Write Query
update dbo.Orders set Freight = %SHIPPINGCHARGES% where OrderID = %RecordID%Northwind Example Database: Access
Retrieving the Ship To information
SELECTo.OrderID as RecordID,o.ShipName as ContactName,c.CompanyName as CompanyName,o.ShipAddress as Address1,o.ShipCity as City,o.ShipRegion as State,o.ShipPostalCode as ZIP,o.ShipCountry as Country,c.Phone as PhoneFROM orders oLEFT OUTER JOIN Customers c ON c.CustomerID = o.CustomerIDWHERE o.OrderID LIKE '%SEARCHPARAM%%'Writing the Shipping Charges Back to the Northwind Database
update Orders set Freight = %SHIPPINGCHARGES% where OrderID = %RecordID%
Microsoft Dynamics GP (aka Great Plains)
Getting the ship to information based on the Sales Order number:
selectSopNumbe as RecordID,CustName as CompanyName,ShipToName as ContactName,Address1 as Address1,Address2 as Address2,Address3 as Address3,City as City,State as State,ZipCode as ZIP,Country as Country,substring(PhNumbr1,1,10) as Phone,FaxNumbr as FaxFROM dbo.SOP10100WHERE SopNUMBE LIKE '%SEARCHPARAM%%'
Writing Back the Tracking Number and Cost
DECLARE @SOPType intDECLARE @CommentsExist intDECLARE @RecID varchar(100)DECLARE @Comments varchar(2000)DECLARE @TrackingNumber varchar(100)DECLARE @PtrVal binary(16)SET @RecID = '%RecordID%'SET @TrackingNumber = '%SHIPPINGCARRIER%:%TRACKINGNUMBER%'SET @Comments = '%SHIPPINGSERVICE% TRK:%TRACKINGNUMBER% ' SELECT @SOPType=SOPTYPE FROM dbo.SOP10100 WHERE SOPNumbe = @RecIDIF (@SOPType > 0) BEGINSELECT @CommentsExist=Count(*) FROM dbo.SOP10106 WHERE SOPNumbe = @RecIDIF (@CommentsExist > 0) BEGINSELECT @PtrVal=TEXTPTR(CMMTTEXT) FROM dbo.SOP10106 WHERE SOPNumbe = @RecIDUPDATETEXT dbo.SOP10106.CMMTTEXT @PtrVal 0 0 @CommentsEND ELSE BEGININSERT INTO dbo.SOP10106 (SOPTYPE, SOPNUMBE, CMMTTEXT) VALUES ( @SOPType, @RecID, @Comments)ENDINSERT INTO dbo.SOP10107 (SOPTYPE, SOPNUMBE, Tracking_Number) VALUES ( @SOPType, @RecID, @TrackingNumber)END
Descartes ShipRush SQL Script for Write-Back to Microsoft GP v8
DECLARE @SOPType intDECLARE @CommentsExist intDECLARE @RecID varchar(100)DECLARE @Comments varchar(2000)DECLARE @TrackingNumber varchar(100)DECLARE @PtrVal binary(16) SET @RecID = '%RecordID%'SET @TrackingNumber = '%SHIPPINGCARRIER%:%TRACKINGNUMBER%'SET @Comments = '%SHIPPINGSERVICE% TRK:%TRACKINGNUMBER% ' SELECT @SOPType=SOPTYPE FROM dbo.SOP10100WHERE SOPNumbe = @RecID IF (@SOPType > 0) BEGINSELECT @CommentsExist=Count(*) FROM dbo.SOP10106WHERE SOPNumbe = @RecIDIF (@CommentsExist > 0) BEGINSELECT @PtrVal=TEXTPTR(CMMTTEXT) FROM dbo.SOP10106WHERE SOPNumbe = @RecIDUPDATETEXT dbo.SOP10106.CMMTTEXT @PtrVal 0 0 @CommentsEND ELSE BEGININSERT INTO dbo.SOP10106(SOPTYPE, SOPNUMBE, CMMTTEXT) VALUES( @SOPType, @RecID, @Comments)END INSERT INTO dbo.SOP10107 (SOPTYPE, SOPNUMBE, Tracking_Number)VALUES ( @SOPType, @RecID, @TrackingNumber)END
Microsoft Dynamics SL (aka Solomon) Example
Reading the Ship To Information
SELECTS.OrdNbr as RecordID,H.ShipName as CompanyName,A.Name as ContactName,A.Addr1 as Address1,A.Addr2 as Address2,A.City as City,A.EmailAddr as EMail,A.State as State,A.Zip as ZIP,A.Country as Country,A.Phone as Phone,A.Fax as FaxFROM SOSched S WITH (NOLOCK)LEFT JOIN SOHeader H WITH (NOLOCK) ON H.CpnyID = S.CpnyID AND H.OrdNbr = S.OrdNbrLEFT OUTER JOIN SOAddress A WITH (NOLOCK) ON (A.CustId = H.CustID) and (A.ShipToId = H.ShipToID)WHERE(S.OrdNbr LIKE '%SEARCHPARAM%%')Writing Back the Tracking Number
DECLARE @RecID varchar(100)DECLARE @CompanyNumber varchar(100)DECLARE @TrackingNumber varchar(100)SET @RecID = '%RecordID%'SET @TrackingNumber = '%SHIPPINGCARRIER%:%TRACKINGNUMBER%'SET @CompanyNumber = '0060'exec ADG_SOEvent_Create @CompanyNumber, @TrackingNumber, 'CSHP', @RecID, '', '', ''
ASPDotNetStorefront
Reading the Ship to Information from the Order
SELECTOrderNumber as RecordID,ShippingFirstname + ' ' + shippinglastname as ContactName,ShippingCompany as CompanyName,ShippingAddress1 as Address1,ShippingAddress2 as Address2,ShippingSuite as Address3,ShippingCity as City,ShippingState as State,ShippingZip as ZIP,ShippingCountry as Country,ShippingPhone as Phone,Email as Email,'C:Temp11pound.zpk' as ShippingTemplateFROM dbo.ordersWHERE ordernumber = %SEARCHPARAM%
Writing Back the Tracking Number and Shipping Service to the Storefront Database
Update orders set ShippingTrackingNumber = '%TRACKINGNUMBER%' where ordernumber = %RecordID%GOUpdate orders set ShippingMethod = '%SHIPPINGSERVICE%' where ordernumber = %RecordID%GO
Microsoft Retail Management System (aka RMS or MSRMS)
For Microsoft RMS, a special kit can be downloaded with SQL and sample ZPK templates.
This first set of scripts revolves around the RMS Shipping Queue. Sales must be tagged for shipping in the usual RMS way for this to work. Note that this is the only way to save tracking information for sales:
SELECTs.TransactionNumber as RecordID,s.[name] as ContactName,s.Company as CompanyName,s.Address as Address1,s.Address2 as Address2,s.City as City,s.State as State,s.ZIP as ZIP,s.Country as Country,s.PhoneNumber as Phone,s.EmailAddress as EMailFROM Shipping swheres.TransactionNumber LIKE '%SEARCHPARAM%%'The above will find any order. To find only unprocessed shipments, change the 'where' clause above to:
where s.TransactionNumber LIKE '%SEARCHPARAM%%' AND DateProcessed is NULL
Writing Back the Tracking Number and Marking the Transaction as Shipped
UPDATE ShippingSet TrackingNumber = '%TrackingNumber%',Notes = '%SHIPPINGSERVICE% TRK:%TRACKINGNUMBER% Cost: %SHIPPINGCHARGES%',DateProcessed = getdate()-- Optional Section. Uncomment to enable/*,carriername = '%ShippingCarrier%',ServiceName = '%ShippingService%',TotalWeight = %ShippingWeight%*/where transactionnumber = %RecordID%
This next query will work for read-access to RMS, whether or not the transaction was marked for shipping. However there is no place to write back the tracking number, so that is not present here.
DECLARE @UseShipTo INTselect @UseShipTo=t.ShipToID from [transaction] twhere t.TransactionNumber = 85 --'%SEARCHPARAM%'IF (@UseShipTo = 0) BEGIN-- This means that the default Customer address is used for-- this xaction, from the Customer tableSELECTt.TransactionNumber as RecordID,c.firstname + ' ' + c.lastname as ContactName,c.Company as CompanyName,c.Address as Address1,c.Address2 as Address2,c.City as City,c.State as State,c.ZIP as ZIP,c.Country as Country,c.PhoneNumber as Phone,c.EmailAddress as EMailFROM Customer c, [transaction] twheret.CustomerID = c.IDand t.TransactionNumber = 85 --'%SEARCHPARAM%%'ENDIF (@UseShipTo <> 0) BEGIN-- Follow ShipToIDSELECTt.TransactionNumber as RecordID,s.[name] as ContactName,s.Company as CompanyName,s.Address as Address1,s.Address2 as Address2,s.City as City,s.State as State,s.ZIP as ZIP,s.Country as Country,s.PhoneNumber as Phone,s.EmailAddress as EMailFROM ShipTo s, [transaction] twheret.ShipToID = s.IDand t.TransactionNumber = 85 --'%SEARCHPARAM%%'END
Next: SQL Webstore - Programming Notes