Solved

T-SQL Extracting Distinct Records

Posted on 2014-02-24
4
787 Views
Last Modified: 2014-02-24
Hello:

Below is my T-SQL query and attached are the results of running the query.  Until I added the last column, DSCRIPTN, I only received four rows of data.  Four, indeed, is the correct number.  I'm surprised that adding just one new column from the same table as other columns caused this.
 
Unfortunately, I do need the data from the DSCRIPTN column as well.  

I tried using the "DISTINCT" keyword.  But, that did not solve the problem.

How do I allow for this last column but have the correct number of rows returned, at the same time?

Thanks!

TBSupport

SELECT AAG30000.JRNENTRY, AAG30000.aaTRXSource, AAG30001.DEBITAMT, AAG30001.CRDTAMNT, GL00105.ACTNUMST, GL00100.ACTDESCR, AAG00401.aaTrxDimCode, AAG00401.aaTrxDimCodeDescr,
GL20000.ORMSTRNM, GL20000.TRXDATE, GL20000.DSCRIPTN
FROM AAG30003
INNER JOIN AAG30000 on
AAG30000.aaGLHdrID =  AAG30003.aaGLHdrID
 INNER JOIN EBSGP..AAG30001
 on
 AAG30000.aaGLHdrID =  AAG30001.aaGLHdrID
  INNER JOIN [EBSGP]..GL00100
 on
 AAG30001.ACTINDX =  GL00100.ACTINDX
   INNER JOIN [EBSGP]..GL00105
 on
 GL00100.ACTINDX =  GL00105.ACTINDX
 INNER JOIN EBSGP..AAG00401
 on
 AAG30003.[aaTrxDimID] =  AAG00401.[aaTrxDimID] and
 AAG30003.aaTrxCodeID = AAG00401.aaTrxDimCodeID
 INNER JOIN GL20000 ON
 AAG30000.JRNENTRY = GL20000.JRNENTRY
where AAG30000.JRNENTRY = '80125'
GROUP BY AAG30001.aaGLDistID, AAG30000.JRNENTRY, AAG30000.aaTRXSource, AAG30001.DEBITAMT, AAG30001.CRDTAMNT, GL00105.ACTNUMST, GL00100.ACTDESCR, AAG00401.aaTrxDimCode, AAG00401.aaTrxDimCodeDescr,
GL20000.ORMSTRNM, GL20000.TRXDATE, GL20000.DSCRIPTN
AA.docx
0
Comment
Question by:TBSupport
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:John_Vidmar
ID: 39883513
You have no aggregate-functions but you have a group-by clause... I would eliminate the group-by and optionally add distict to the select-clause.
0
 
LVL 1

Author Comment

by:TBSupport
ID: 39883568
Hi John_Vidmar:

I get the same result.

TBSupport
0
 
LVL 11

Accepted Solution

by:
John_Vidmar earned 500 total points
ID: 39883611
INNER JOIN GL20000 ON
 AAG30000.JRNENTRY = GL20000.JRNENTRY

The above statement does not uniquely identify a GL20000.DSCRIPTN for a GL20000.JRNENTRY... would you be able to add additional filters to the on-clause against AAG30000 (or another table) ?
0
 
LVL 1

Author Comment

by:TBSupport
ID: 39883741
Thanks, John_Vidmar!

You led me down the right path!  I simply took the phrase "GL20000.DSCRIPTN" and made it "GL20000_1.DSCRIPN".  To do so, I added the following clause:

 INNER JOIN GL20000 AS GL20000_1
 ON AAG30001.ACTINDX = GL20000_1.ACTINDX

Thanks, Again!

TBSupport
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

It is helpful to note: This is a cosmetic update and is not required, but should help your reports look better for your boss.  This issue has manifested itself in SSRS version 3.0 is where I have seen this behavior in.  And this behavior is only see…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

724 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