SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Help! How to return results that don't repeat
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

wleonard
Starting Member

USA
30 Posts

Posted - 12/18/2012 :  15:17:55  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/18/2012 :  16:15:12  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 12/19/2012 :  03:57:37  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000