[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

T-SQL Extracting Distinct Records

Posted on 2014-02-24
4
Medium Priority
?
801 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 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

650 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