Solved

T-SQL Bogus Rows

Posted on 2013-01-07
4
417 Views
Last Modified: 2013-01-13
The programming within the attached Notepad file B is a view called Tri_view_CashBasis4B.  This view is contained within the programming in the view in Notepad file A.

Attached are the results of running each in the SQL Studio.  "A" is supposed to be the final result.  Rows 4 and 6 in A, though, are wrong.  The results of the two views are to correspond based on the third string of the account number field in each.  And, A should only have the debit amounts in B.

How do I fix the linking or whatever in A so that it pulls the correct information from B?
B.txt
A.txt
B.xlsx
A.xlsx
0
Comment
Question by:TBSupport
  • 3
4 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 38754711
could you please post the information in the question?
some people are not too excited about downloading xlsx files...
0
 
LVL 1

Author Comment

by:TBSupport
ID: 38755913
Sure!  I will post all four items, as follows:

Here is B.xlsx:
Here is the image of A.xlsx (Hope this helps)

Here is A.xlsx:
Here is the image of B.xlsx (Hope this helps)
Here is B.txt:
SELECT DISTINCT
                      dbo.GL20000.TRXDATE AS GL_Date, dbo.GL00105.ACTNUMST AS Account_Number, dbo.GL20000.DEBITAMT AS Debit,
                      dbo.GL20000.CRDTAMNT AS Credit, dbo.GL20000.ORMSTRID AS Originating_Master_ID, dbo.PM30600.VCHRNMBR AS Originating_Master_No,
                      dbo.GL20000.ORDOCNUM AS Originating_Doc_No, dbo.PM30200.DOCNUMBR + dbo.PM30200.TRXDSCRN AS Reference,
                      dbo.PM30300.APFRDCNM AS Apply_From_Doc_No, dbo.PM30200.DOCAMNT AS Applied_Amount, dbo.PM30200.DOCNUMBR AS REFERENCE1
FROM         dbo.PM30200 LEFT OUTER JOIN
                      dbo.PM30300 ON dbo.PM30200.VENDORID = dbo.PM30300.VENDORID AND dbo.PM30200.DOCNUMBR = dbo.PM30300.APTODCNM LEFT OUTER JOIN
                      dbo.PM30600 ON dbo.PM30600.VCHRNMBR = dbo.PM30300.APTVCHNM AND dbo.PM30600.VENDORID = dbo.PM30300.VENDORID LEFT OUTER JOIN
                      dbo.GL20000 ON dbo.PM30600.VENDORID = dbo.GL20000.ORMSTRID AND dbo.PM30600.VCHRNMBR = dbo.GL20000.ORCTRNUM AND
                      dbo.PM30600.PSTGDATE = dbo.GL20000.TRXDATE LEFT OUTER JOIN
                      dbo.GL00105 ON dbo.GL20000.ACTINDX = dbo.GL00105.ACTINDX INNER JOIN
                      dbo.GL00100 ON dbo.GL00105.ACTINDX = dbo.GL00100.ACTINDX
WHERE     (dbo.PM30200.DOCTYPE = '1')
AND GL20000.ORMSTRID = 'FOR200'
AND PM30300.APFRDCNM = '018859'


Here is A.txt:
SELECT DISTINCT
GL20000.TRXDATE AS [GL_Date], GL00105.ACTNUMST AS [Account_Number],
GL20000.DEBITAMT AS [Debit], GL20000.CRDTAMNT AS [Credit],
GL20000.ORMSTRID AS [Originating_Master_ID],
PM30600.VCHRNMBR AS [Originating_Master_No],
GL20000.ORDOCNUM AS [Originating_Doc_No],
TRI_view_CashBasis4B.Reference AS [Reference],
GL20000.ORDOCNUM AS [Apply_From_Doc_No], PM30200.DOCAMNT AS [Applied_Amount]
FROM  GL20000
LEFT OUTER JOIN
PM30600 ON PM30600.VENDORID = GL20000.[ORMSTRID] AND PM30600.VCHRNMBR = GL20000.ORCTRNUM AND
PM30600.PSTGDATE = GL20000.TRXDATE
LEFT OUTER JOIN
PM30300 ON PM30600.VCHRNMBR = PM30300.APTVCHNM AND PM30600.VENDORID = PM30300.VENDORID
LEFT OUTER JOIN
PM30200 ON GL20000.ORMSTRID = PM30200.[VENDORID] AND GL20000.ORDOCNUM = PM30200.[DOCNUMBR]
LEFT OUTER JOIN
GL00105 ON GL20000.[ACTINDX] = GL00105.[ACTINDX] INNER JOIN
GL00100 ON GL00105.[ACTINDX] = GL00100.[ACTINDX]
INNER JOIN
TRI_view_CashBasis4B ON GL20000.ORMSTRID = TRI_view_CashBasis4B.Originating_Master_ID AND
GL20000.ORDOCNUM = TRI_view_CashBasis4B.Apply_From_Doc_No
WHERE     GL20000.SOURCDOC = 'PMCHK' AND GL00105.ACTNUMST LIKE '%C'
AND GL20000.DEBITAMT = TRI_view_CashBasis4B.Debit AND
GL20000.CRDTAMNT = TRI_view_CashBasis4B.Credit
and gl20000.ORMSTRID = 'FOR200' AND
GL20000.ORDOCNUM = '018859'
B.PNG
B.PNG
0
 
LVL 1

Accepted Solution

by:
TBSupport earned 0 total points
ID: 38756393
Disregard.  I figured it out.  Here is the solution:

The following clause needs to be put in "A":

and SUBSTRING(dbo.TRI_view_CashBasis4B.Account_Number, 11, 5)
= SUBSTRING(GL00105.ACTNUMST, 11, 5)
0
 
LVL 1

Author Closing Comment

by:TBSupport
ID: 38771616
I simply needed to determine how to configure "substring" to tie the general ledger account numbers together.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tempdb latch contention 12 47
Using CTE to insert records into a table 2 26
MS SQL Inner Join - Multiple Join Parameters 2 17
SQL Server Question 5 25
Automatically creating a Trello card using data from a Microsoft Dynamics CRM record turned out to be an easy project that yielded great results.  Here's how I did this for an internal team at General Code.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now