ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   prevent duplicate results (database query) (https://www.excelbanter.com/excel-programming/311385-prevent-duplicate-results-database-query.html)

Dan Wasser[_2_]

prevent duplicate results (database query)
 
I'm using Excel's database query to get a list of accounts
(ACCTNAME) based on certain criteria (Like INN% and Like
MSS%). But, because INN and MSS occur multiple times
within the same account, Excel is returning those account
names multiple times. But I need (want) the account name
only once. Is there a "distinct" statement or some other
rule/criteria that I can build into the database query to
prevent the account name from appearing multiple times?
Here's the SQL statement from within MS Query (within
Excel):


SELECT ARACCT.ACCTNAME, ARACCT.SALES, ARACCT.ACCTSTAT,
ARACCT.CITY, ARACCT.STATE, ARACCT.OFFTELE,
ARACCT.IHPAYSTAT, ARACCT.IHPAYCMNT, ARTRAN.TRANCODE
FROM ihacct.dbo.ARACCT ARACCT, ihacct.dbo.ARTRAN ARTRAN
WHERE ARACCT.ARCODE = ARTRAN.ARCODE AND ((ARTRAN.TRANCODE
Like 'INN%') OR (ARTRAN.TRANCODE Like 'MSS%'))
ORDER BY ARACCT.ACCTNAME


Jim Thomlinson[_3_]

prevent duplicate results (database query)
 
Interestingly enough you anwered your own question. After the work select in
the SQL add the work DISTINCT. if I correctly understand your question that
will work.

"Dan Wasser" wrote:

I'm using Excel's database query to get a list of accounts
(ACCTNAME) based on certain criteria (Like INN% and Like
MSS%). But, because INN and MSS occur multiple times
within the same account, Excel is returning those account
names multiple times. But I need (want) the account name
only once. Is there a "distinct" statement or some other
rule/criteria that I can build into the database query to
prevent the account name from appearing multiple times?
Here's the SQL statement from within MS Query (within
Excel):


SELECT ARACCT.ACCTNAME, ARACCT.SALES, ARACCT.ACCTSTAT,
ARACCT.CITY, ARACCT.STATE, ARACCT.OFFTELE,
ARACCT.IHPAYSTAT, ARACCT.IHPAYCMNT, ARTRAN.TRANCODE
FROM ihacct.dbo.ARACCT ARACCT, ihacct.dbo.ARTRAN ARTRAN
WHERE ARACCT.ARCODE = ARTRAN.ARCODE AND ((ARTRAN.TRANCODE
Like 'INN%') OR (ARTRAN.TRANCODE Like 'MSS%'))
ORDER BY ARACCT.ACCTNAME



dan

prevent duplicate results (database query)
 
Thanks, Jim! It worked perfectly.
Dan

-----Original Message-----
Interestingly enough you anwered your own question. After

the work select in
the SQL add the work DISTINCT. if I correctly understand

your question that
will work.

"Dan Wasser" wrote:

I'm using Excel's database query to get a list of

accounts
(ACCTNAME) based on certain criteria (Like INN% and

Like
MSS%). But, because INN and MSS occur multiple times
within the same account, Excel is returning those

account
names multiple times. But I need (want) the account

name
only once. Is there a "distinct" statement or some

other
rule/criteria that I can build into the database query

to
prevent the account name from appearing multiple

times?
Here's the SQL statement from within MS Query (within
Excel):


SELECT ARACCT.ACCTNAME, ARACCT.SALES, ARACCT.ACCTSTAT,
ARACCT.CITY, ARACCT.STATE, ARACCT.OFFTELE,
ARACCT.IHPAYSTAT, ARACCT.IHPAYCMNT, ARTRAN.TRANCODE
FROM ihacct.dbo.ARACCT ARACCT, ihacct.dbo.ARTRAN ARTRAN
WHERE ARACCT.ARCODE = ARTRAN.ARCODE AND

((ARTRAN.TRANCODE
Like 'INN%') OR (ARTRAN.TRANCODE Like 'MSS%'))
ORDER BY ARACCT.ACCTNAME


.



All times are GMT +1. The time now is 05:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com