![]() |
![]() |
Technical Support
|
![]() |
These queries involve vendors, types of vendors, accounts payables, items purchased from vendors and vendor returns. When vendors are used to perform services for customers that are facilitated by the company, this area also included those details. It also includes payments made to tax authorities as a result of payroll transactions.
Transaction types that involve vendors are (alphabetically): CardChrg, Check, ItemRcpt, Journal, LiabPymt, TaxPymt, VendBill, VendCred, and VendPymt.
You can create very detailed historical accounts payable reports. When combined with inventory items, you can create any type of purchase history needed. These queries can also be used to collect information about services performed by vendors.
The queries listed below are generally arranged from simple to complex. Normally, queries that get their data from only 1 table and do not aggregate any fields are listed first. To get full benefit of these queries and create your own queries - you should understand joins (where multiple tables are combined into a single table) and aggregation (where numeric columns from multiple rows are combined into 1 column). These concepts are not as difficult as they first appear and a web search for 'SQL' and 'join' or 'aggregation' will bring up hundreds of tutorials.
Where a line of dashes (like: --------------------) appears in a query, a useful variation of the query is shown. It could be very simple, such as changing the sort order of the output - or more complex, such as a complete alternate query. Where a single line in the query has the character: # as it's leftmost character - that line is a comment and is not processed by our query runner.
SELECT sName, sCompanyName, sFirstName,
sMidName, sLastName, sCity, sState,
sContact, sPhone, sEmail, bInactive
FROM vVendor
ORDER BY sName
SELECT sName,
mCreditLimit AS CreditLimit,
-mBalance AS Balance,
(mCreditLimit - (-mBalance)) AS CreditAvailable
FROM vVendor
WHERE mCreditLimit IS NOT NULL
AND mBalance IS NOT NULL
ORDER BY sName
SELECT COUNT(sEmail) AS CountWithEmail,
COUNT(*) AS TotalVendorss,
FORMAT((COUNT(sEmail) / COUNT(*)), "00.0%")
AS PercentWithEmail
FROM vVendor
SELECT
vVendType.sFullName AS VendorTypeName,
vVendor.sName AS VendorName
FROM
vVendType LEFT JOIN vVendor
ON vVendType.nKey = vVendor.kVendType
ORDER BY vVendType.nReportSort,
vVendType.sFullName,
vVendor.sName
SELECT
YEAR(dDate) AS Year,
CHOOSE(FORMAT(dDate, "w"),
"Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday")
AS DayOfWeek,
aAccount.sFullName,
SUM(aTranLine.mAmount) AS TotalDollars
FROM
aAccount INNER JOIN aTranLine
ON aAccount.nKey = aTranLine.kAcct
WHERE YEAR(dDate) IN (2012, 2013)
AND bNoPost = False
AND aAccount.sAcctType = "Expense"
GROUP BY
YEAR(dDate),
FORMAT(dDate, "w"),
aAccount.sFullName
ORDER BY
YEAR(dDate),
FORMAT(dDate, "w")
SELECT
sName, sState,
COUNT(dDate) AS Count_Of_Trans
FROM vVendor LEFT JOIN aTranLine
ON vVendor.nKey = aTranLine.kEntity
GROUP BY sName, sState
HAVING COUNT(dDate) = 0
SELECT
sName, sCity, sState,
MIN(dDate) AS FirstDate,
MAX(dDate) AS LastDate,
COUNT(dDate) AS CountTrans
FROM vVendor INNER JOIN aTranLine
ON vVendor.nKey = aTranLine.kEntity
WHERE bDocMain = True
GROUP BY sName, sCity, sState
HAVING COUNT(dDate) > 0
# ORDER BY sName
ORDER BY COUNT(dDate)
SELECT aTranDoc.dDate,
aTranDoc.sTranType,
aTranDoc.sFlags,
aTranLine.kAcct,
aTranLine.sAcctType,
aTranLine.kEntity,
aTranLine.sEntityType,
aTranLine.mAmount,
aTranLine.dPaidInFull,
aTranLine.mStillOwing
FROM aTranDoc INNER JOIN aTranLine
ON aTranDoc.nKey = aTranLine.kDoc
WHERE
(aTranLine.dPaidInFull IS NOT NULL
OR
aTranLine.mStillOwing > 0)
ORDER BY aTranDoc.sTranType
# aTranLine.bDocMain = True
# AND
# aTranLine.mAmount <> 0
# AND
# bNoPost = False
----------------------------------------------
AND
aTranLine.sTranType IN
('CustChrg', 'CustInvc', 'VendBill')
((aTranDoc.sFlags LIKE '*F*')
OR
(aTranLine.dPaidInFull IS NOT NULL)
OR
(aTranLine.mStillOwing <> 0))
SELECT aTranDoc.sTranType,
COUNT(*) AS TranTypeCount
FROM aTranDoc LEFT JOIN aTranLine
ON aTranDoc.nKey = aTranLine.kDoc
WHERE
aTranLine.bDocMain = True
AND
aTranLine.bNoPost = False
AND
aTranLine.kEntity IN (SELECT nKey FROM vVendor)
GROUP BY aTranDoc.sTranType
------------------------------------------------
OR
aTranLine.kEntity2 IN (SELECT nKey FROM cCustJob)
SELECT vVendor.nKey,
sName, mBalance,
SUM(mAmount) AS SumOfmAmount,
mBalance - SUM(mAmount) AS Difference,
COUNT(mAmount) AS CountOfmAmount
FROM vVendor INNER JOIN aTranLine
ON vVendor.nKey = aTranLine.kEntity
WHERE (kAcct IN (
SELECT nKey
FROM aAccount
WHERE sAcctType = 'AcctPay' ))
AND
aTranLine.bNoPost = False
GROUP BY vVendor.nKey, sName, mBalance
ORDER BY sName
SELECT
sPhone AS PhoneNumber,
sEntityType AS CompanyType,
sFullName AS Name,
sBillCity AS City, sBillState AS State
FROM cCustJob
WHERE sPhone IS NOT NULL
UNION
SELECT
sPhone AS PhoneNumber,
'Vendor' AS CompanyType,
sName AS Name,
sCity AS City, sState AS State
FROM vVendor
WHERE sPhone IS NOT NULL
UNION
SELECT
sPhone AS PhoneNumber,
'Employee' AS CompanyType,
sName AS Name,
sCity AS City, sState AS State
FROM pEmployee
WHERE sPhone IS NOT NULL
ORDER BY PhoneNumber
SELECT
vVendor.sName,
vInvtItem.sFullName,
vInvtItem.sItemType,
SUM(aTranLine.rItemCount) AS TotalUnits
FROM
(vVendor INNER JOIN aTranLine
ON vVendor.nKey = aTranLine.kEntity2)
INNER JOIN vInvtItem
ON aTranLine.kItem = vInvtItem.nKey
WHERE aTranLine.sItemType
IN ("InvtPart", "NonInvtPart")
GROUP BY
vVendor.sName,
vInvtItem.sFullName,
vInvtItem.sItemType
ORDER BY vVendor.sName, vInvtItem.sFullName
SELECT
aAccount.nReportSort,
aAccount.sAcctType,
aAccount.sFullName,
YEAR(dDate) AS Year,
vVendor.sName,
SUM(aTranLine.mAmount) AS TotalDollars
FROM
(vVendor INNER JOIN aTranLine
ON vVendor.nKey = aTranLine.kEntity2)
INNER JOIN aAccount
ON aTranLine.kAcct = aAccount.nKey
WHERE vVendor.sName
IN ("Amazon", "Costco Wholesale",
"Fred Meyer", "Lowe's", "NewEgg",
"Paypal", "Target", "Walmart")
AND YEAR(dDate) IN (2010, 2011, 2012)
AND bNoPost = False
GROUP BY
aAccount.nReportSort,
aAccount.sAcctType,
aAccount.sFullName,
YEAR(dDate),
vVendor.sName
SELECT
vVendor.sName,
YEAR(dDate) AS Year,
aAccount.nReportSort,
aAccount.sAcctType,
aAccount.sFullName,
SUM(aTranLine.mAmount) AS TotalDollars
FROM
(vVendor INNER JOIN aTranLine
ON vVendor.nKey = aTranLine.kEntity2)
INNER JOIN aAccount
ON aTranLine.kAcct = aAccount.nKey
WHERE vVendor.sName
IN ("Amazon", "Costco Wholesale",
"Fred Meyer", "Lowe's", "NewEgg",
"Paypal", "Target", "Walmart")
AND YEAR(dDate) IN (2010, 2011, 2012)
AND bNoPost = False
GROUP BY
vVendor.sName,
YEAR(dDate),
aAccount.sAcctType,
aAccount.sFullName,
aAccount.nReportSort
ORDER BY
vVendor.sName,
YEAR(dDate),
aAccount.nReportSort
SELECT
cCustJob.sFullName AS CustJob,
aTranLine.dDate,
aTranLine.mAmount,
vVendor.sName AS Vendor,
vInvtItem.sFullName AS Item,
vInvtItem.sItemType,
aTranLine.sTranType,
aTranLine.sBillableStatus
FROM
((vVendor INNER JOIN aTranLine
ON vVendor.nKey = aTranLine.kEntity2)
INNER JOIN vInvtItem
ON aTranLine.kItem = vInvtItem.nKey)
INNER JOIN cCustJob
ON aTranLine.kEntity = cCustJob.nKey
WHERE aTranLine.sBillableStatus <> 'NotBillable'
ORDER BY CustJob, dDate
----------------------------------------------
WHERE aTranLine.sBillableStatus = 'Billable'
WHERE aTranLine.sBillableStatus IS NOT NULL