This may be the strangest thing I've ever seen.
We have sql server 2012 and a data warehouse.
Fact table contains more than 1 billion rows which are based on monthly partitions.
Those 2 queries returns almost same values. Difference is that second one filters additionally by Invoice Number.
select miesiacsprzedazy Month,Ilosc Volume,fs.faktkey [Key],fs.wartoscnetto NetValue,NrFaktury InvoiceNum,FakturaId from faktsprzedaz fs join wymkontrahent wk on fs.kontrahentkey=wk.kontrahentkey where miesiacsprzedazy=20130301 and wk.nip like '5342405501%' and TaryfaKey in (select taryfakey from wymtaryfa where taryfakodzrodlowy='TR') and SkladnikKey=1 --and NrFaktury='145106824/1R/2013' order by FakturaId,NrLinii select miesiacsprzedazy Month,Ilosc Volume,fs.faktkey [Key],fs.wartoscnetto NetValue,NrFaktury InvoiceNum,FakturaId from faktsprzedaz fs join wymkontrahent wk on fs.kontrahentkey=wk.kontrahentkey where miesiacsprzedazy=20130301 and wk.nip like '5342405501%' and TaryfaKey in (select taryfakey from wymtaryfa where taryfakodzrodlowy='TR') and SkladnikKey=1 and NrFaktury='145106824/1R/2013' order by FakturaId,NrLiniiResult is quite a surprise for me and I'm starting to be a little bit terrified:
Fact table Keys are Month and Key columns. As you can see, without any aggregation NetValue for same unique row is different in those two queries.
Any help will be appreciated as I said, it's quite shocking for me.
Maciej