Solved

T-SQL Extracting Distinct Records

Posted on 2014-02-24
4
750 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
  • 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Detach & Attach 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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
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.

705 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

19 Experts available now in Live!

Get 1:1 Help Now