Re: Why Same query results in two different # in SQL Server vs MS Access



On Feb 20, 6:09 pm, Erland Sommarskog <esq...@xxxxxxxxxxxxx> wrote:
 (dsdevonso...@xxxxxxxxx) writes:
I have one simple query joining two tables with left outer join on 3
fields and using MIN on two fields. These two tables have lot of data
about 3 mil in total. I am trying to migrate db from MS Access to SQL
2005. I get about 689000 rows in SQL Server, vs 863000 rows in MS
Access.

SELECT T1.[MON], T1.[ANUM], T2.[ANUM], MIN ( T1.[OCD]), MIN(T1.
[STATE]), T1.COUNT

FROM T1 INNER JOIN T2  ON T1.MON = T2.MON AND T1.[OCD] = T2.[OCD] AND
T1.[STATE] = T2.[STATE]

WHERE T1.[REASON] <> 'SOMETHING' AND T2.[REASON] <> 'SOMETHING'

GROUP BY T1.[MON], T1.[ANUM], T2.[ANUM], T1.COUNT

HAVING T1.[MON] <> '-' AND T1.[ANUM] <> '-'

I have about 30 queries to migrate and I am sort of stuck. Does any
one have any idea ?

Unfortunately, it's impossible to tell what the reason might be from
that scant amount of information. But I could offer some ideas on how
you should proceed to narrow it down.

0) Move the conditions in the HAVING clause to the WHERE clause. At
   least in this particular query, there is no reason for having those
   conditions in the HAVING clause.

1) Remove the GROUP BY (and MIN), and compare the number of rows.
   If the number of rows now are the same(A), there are some issues
   with the grouping as such. If the number of rows still are different
   (and with a bigger total difference), there is an issue in
   the selection (B).

2) (A) Remove columns from the GROUP BY list, and see if the difference
   is due to a certain column.

3) (B) Narrow it down further by removing one of more of the conditions
    from the WHERE clause (including those you moved in from HAVING).

4) (B) If that does not help play with the JOIN part.

At some point it's probably a good idea to narrow down also the dataset,
to see if there some certain data that is causing the difference. For
instance, different handling of lowercase/uppercase, accents etc.

And, oh, you said above that you were joining with outer join, but
above you have an inner join... If you use different join types in
Access and SQL Server, that could be an explanation.

--
Erland Sommarskog, SQL Server MVP, esq...@xxxxxxxxxxxxx

Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx- Hide quoted text -

- Show quoted text -


Hello Erland/Hugo

First of, thank you much for replying. I have made error in typing. I
just have inner join. Not ANY Outer join.
Hugo, to your question, I have some null values in both tables for
MON and Reasons. Total of about 5000 rows between both tables are
having null values.

Is that what causing Access to return more results vs SQL Server ? I
tried including the clause " MON IS NOT NULL " and "Reason IS NOT
NULL" but Access still returns the same number of rows. ? Should I be
doing something different ?

Many thanks again,
JB
.



Relevant Pages

  • Re: access2007 - 3420 - Object invalid or no longer set.
    ... The reason why? ... the use of many functions in the query. ... the query 'qrySelectContact' is a sql server view, ...
    (comp.databases.ms-access)
  • Re: Why Same query results in two different # in SQL Server vs MS Access
    ... it's impossible to tell what the reason might be from ... Move the conditions in the HAVING clause to the WHERE clause. ... Access and SQL Server, ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Howard Stern broadcast of Yoko at UN on Johns 50th birthday
    ... My reason for  criticizing Yoko and Pelosi for that matter is that the ... that your opinions are based on bad information. ...    that your opinions are based on bad information." ... You are being unnecessarily argumentative in your response to me, ...
    (rec.music.beatles)
  • Re: Air America Closes
    ... The reason for the exchange currency switch is because both countries' ...   Damn, sounds like a conspiracy to get rid of the dollar. ... Bra Ha HA, go ahead, chuckle heads, we got the friggin' ...
    (rec.music.classical.guitar)
  • Re: This is absolutely GREAT!!!
    ... Randy, first you back off from one city. ...  That is the reason we have the mess we are in now. ...   you don't like that. ...
    (misc.transport.road)