Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem with incorrect count

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2011-02-21 : 14:28:47
Using the code below, I am getting a count of 7 instead of 6 which is what I'm expecting. Can anyone tell me where 7 is coming from?

Prod_Cat Ord_no entered_dt
502 00119544 20110217
511 00119558 20110217
511 00119565 20110217
511 00119567 20110217
506 00119568 20110217
511 00119569 20110217
NULL 00119570 20110217
502 00119570 20110217
511 00119570 20110217
512 00119570 20110217
NULL 00119572 20110217
502 00119572 20110217
501 00119574 20110217
502 00119574 20110217
502 00119575 20110217
505 00119576 20110217
502 00119577 20110217
511 00119577 20110217



select oeordlin_sql.prod_cat, count(distinct oeordlin_sql.ord_no),oeordhdr_sql.entered_dt
from oeordlin_sql join oeordhdr_sql on oeordlin_sql.ord_type = oeordhdr_sql.ord_type and
oeordlin_sql.ord_no = oeordhdr_sql.ord_no
where oeordlin_sql.prod_cat = '511' and oeordhdr_sql.entered_dt = '20110217'
group by prod_cat, entered_dt

dmilam
Posting Yak Master

185 Posts

Posted - 2011-02-21 : 14:51:36
It may be counting from this row also:
NULL 00119570 20110217
because Ord_no matches to one for 511
Go to Top of Page
   

- Advertisement -