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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Help! How to return results that don't repeat

Author  Topic 

wleonard
Starting Member

30 Posts

Posted - 2012-12-18 : 15:17:55
Hello. My assignment entails simply returning results that ONLY contain values = 'QCBIN' OR '' OR IS NULL. Here is my code. I am not getting the correct results.

SELECT DISTINCT tblbincontents.inp_SHORT_ITEM_NUMBER FROM
tblBinContents LEFT OUTER JOIN tblInventoryPrimary ON
tblBinContents.inp_SHORT_ITEM_NUMBER = tblInventoryPrimary.inp_SHORT_ITEM_NUMBER
WHERE (bin_CODE = 'QCBIN') OR (bin_CODE = '')
OR (bin_CODE IS NULL) AND tblInventoryPrimary.ist_INVENTORY_STATUS_CODE <> 'D'
GROUP BY tblbincontents.bin_CODE, tblBinContents.inp_SHORT_ITEM_NUMBER HAVING 1 = count(*)

Cheers.

Will Leonard

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-12-18 : 16:15:12
It should give you only one row each for a given combination of bin_CODE and inp_SHORT_ITEM_NUMBER. Is that not what you are seeing? Or is that not what you are looking to get?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-19 : 03:57:37
perhaps you meant this??

SELECT tblbincontents.inp_SHORT_ITEM_NUMBER FROM
tblBinContents LEFT OUTER JOIN tblInventoryPrimary ON
tblBinContents.inp_SHORT_ITEM_NUMBER = tblInventoryPrimary.inp_SHORT_ITEM_NUMBER
WHERE (bin_CODE = 'QCBIN') OR (bin_CODE = '')
OR (bin_CODE IS NULL) AND tblInventoryPrimary.ist_INVENTORY_STATUS_CODE <> 'D'
GROUP BY tblBinContents.inp_SHORT_ITEM_NUMBER HAVING 1 = count(*)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -