Solved

T-SQL Extracting Distinct Records

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Written by Valentino Vranken. Introduction: The first step of creating a SQL Server Reporting Services (SSRS) report involves setting up a connection to the data source and programming a dataset to retrieve data from that data source.  The data…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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