Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Nightmare legacy query to unravel

$
0
0
Afternoon all!

This is going to get long. A user has flagged a potential problem with an SQL-based application - she's entered a record, and cannot see it where she thinks she should. This application is about 7 years old, built on SQL2000 and Access 2000. Furthermore, it was built in-house by two people who knew little about SQL and Access, and are no longer with the company.

The application is called CCQuID (Credit Control Query Information Database), and is used by Credit Control to record the reasons given for why our customers aren't paying us. The problem that has been flagged is that a query has been entered and is not appearing on the front form. I have checked the design of the form, and the source view's SQL statement is as follows:
Code:

CREATE VIEW dbo.[vssqueryproductline(current)]
AS
SELECT TOP 100 PERCENT
        dbo.SLP15_IN.[Date] AS InvoiceDate
,        dbo.QueryProductLines.QueryTypeID
,        dbo.QueryProductLines.PassedToID
,        dbo.SLP05.CNAM05
,        dbo.SLP05.Account
,        dbo.QueryProductLines.ProductCode
,        dbo.UOM.UOM
,        dbo.QueryProductLines.Quantity
,        dbo.QueryProductLines.PriceInvoiced
,        dbo.QueryProductLines.PriceClaimed
,        dbo.QueryProductLines.InvoiceReference
,        dbo.QueryProductLines.DebitReference
,        dbo.QueryProductLines.Note
,        dbo.QueryProductLines.DatePassed
,        dbo.QueryProductLines.ThisPartCleared
,        dbo.Ledgers.ControllerName
,        dbo.SLP15_IN.SOPN
,        dbo.SLP15_IN.PurchaseOrder
,        dbo.SLP15_IN.DespatchSite
,        dbo.QueryProductLines.DateDetailsEntered
,        dbo.QueryTypes.QueryTypeStatus
,        dbo.PassedTo.PassedTo
,        dbo.QueryProductLines.UOMID
,        dbo.QueryProductLines.QPLID
,        dbo.SLP15_IN.OutstandingAmount AS INOS
,        dbo.SLP15_DN.OutstandingAmount AS DNOS
,        dbo.SLP15_DN.Account AS DNAccount
,        dbo.SLP15_DN.SOPN AS DNSOPN
,        Ledgers_1.ControllerName AS DNControllerName
,        dbo.SLP15_IN.DSEQ
FROM
        dbo.SLP05
FULL OUTER JOIN
        dbo.SLP15_IN
ON
        dbo.SLP05.Account = dbo.SLP15_IN.Account
FULL OUTER JOIN
        dbo.Ledgers
ON
        dbo.SLP05.CRSP05 = dbo.Ledgers.CRSP05
AND
        dbo.SLP05.CRSP05 = dbo.Ledgers.CRSP05
AND
        dbo.SLP05.CRSP05 = dbo.Ledgers.CRSP05
FULL OUTER JOIN
        dbo.SLP15_DN
FULL OUTER JOIN
        dbo.SLP05 SLP05_1
ON
        dbo.SLP15_DN.Account = SLP05_1.Account
FULL OUTER JOIN
        dbo.Ledgers Ledgers_1
ON
        SLP05_1.CRSP05 = Ledgers_1.CRSP05
FULL OUTER JOIN
        dbo.QueryProductLines
LEFT OUTER JOIN
        dbo.QueryTypes
ON
        dbo.QueryProductLines.QueryTypeID = dbo.QueryTypes.QueryTypeID
LEFT OUTER JOIN
        dbo.PassedTo
ON
        dbo.QueryProductLines.PassedToID = dbo.PassedTo.PassedToID
LEFT OUTER JOIN
        dbo.UOM
ON
        dbo.QueryProductLines.UOMID = dbo.UOM.UOMID
ON
        dbo.SLP15_DN.DebitReference = dbo.QueryProductLines.DebitReference
ON
        dbo.SLP15_IN.InvoiceReference = dbo.QueryProductLines.InvoiceReference
WHERE
        (dbo.QueryProductLines.ThisPartCleared = 0)
AND
        (dbo.SLP15_IN.OutstandingAmount <> 0)
OR
        (dbo.QueryProductLines.ThisPartCleared = 0)
AND
        (dbo.SLP15_DN.OutstandingAmount <> 0)
ORDER BY
        InvoiceDate

NB
All I have done is reformat the text - the names are as it was created.
An explanation for the table names would probably be useful:
SLP05 - Customer names and addresses
SLP15_IN - Sales ledger invoice details
Ledgers - Credit controller assignations
SLP15_DN - Sales ledger debit notes details
QueryProductLines - Enquiry SKU details
QueryTypes - Enquiry types
PassedTo - Information on who's dealing with it

So, can anyone unravel this? I tried to construct a diagram of the links, and got lost, but I can have a go at scanning it and uploading it if that would help.

As far as I can see, the important tables for the sake of this problem are QueryProductLines and SLP15_DN - the former holds the product codes being queried, and the latter holds the total amount of the claim. The debit note in question has a record in both tables, yet it does not appear in the view's output. Can a fresh pair of eyes spot what I'm missing?

Viewing all articles
Browse latest Browse all 13329

Trending Articles