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
 Query is having repeated values

Author  Topic 

ramachandran.123
Starting Member

3 Posts

Posted - 2012-11-29 : 01:47:28

Dear Sir
I am having query

select distinct(cetshnumber), INVOICEITEMS.ItemQuantity 'Quantity Manufactured',INVOICEITEMS.ItemQuantity 'Quantity Cleared'
from INVOICEITEMS,invoice,cetsh where invoice.invoicenumber=invoiceitems.invoicenumber and
month(InvoiceDate)=11 and year(InvoiceDate)=2012 group by cetshnumber,INVOICEITEMS.ItemQuantity

I have given distinct but still the cetshnumber value is repeated for each record.


Thanks and Regards
N.Ram

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2012-11-29 : 01:54:55
looks like cetshnumber has multiple entries in other tables your are joining.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-11-29 : 02:46:41
Note that distinct wont work that way. It is applied to entire column set and not on cetshnumber only. If there are m,ultiple ItemQuantity associated to each cetshnumber , the cetshnumber will get repeated. You may need to remove ItemQuantity in GROUP BY cluae and use min or max on it

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -