troubleshooting Question

SQL Query Syntax to find subset plus mainlist

Avatar of rwheeler23
rwheeler23Flag for United States of America asked on
Microsoft SQL Server 2008Microsoft SQL Server 2005
7 Comments1 Solution138 ViewsLast Modified:
I have this query that works fine for one report but now the users want to turn it around. What this query does is find all parts from the primary vendor that are also offered from other vendors. Now what the user want is a list of all parts from the primary regardless of whether they come from another vendor plus to also list those parts that come from other vendors. In one example the current query returns 3,500 records however, there are 30,000 parts that come from this vendor. I need to include the other 26,500 parts.

Sample Data:
ITEMNMBR,VENDORID,LSTORDDT,LSORDQTY,LASTCOST
WIDGET1,VEND1,10/31/13,4,3.0
WIDGET2,VEND1,12/31/13,6,4.0
WIDGET2,VEND2,01/10/14,5,3.5

So in this case, they want to see both WIDGET1 and WIDGET2 where for WIDGET1 there are no other vendors but for WIDGET2 there is another vendor. Currently, my script will only list WIDGET2.

SELECT     V.ITEMNMBR,
                  V.VENDORID AS PRMVENDOR,
                  V.LSTORDDT AS PRMLSTORDDT,
                  V.LSORDQTY AS PRMLSORDQTY,
                  V.LAST_Originating_Cost AS PRMLASTCOST,
                  OV.VENDORID AS ALTVENDOR,
                 OV.LSTORDDT AS ALTLSTORDDT,
                 OV.LSORDQTY AS ALTLSORDQTY,
                 OV.LAST_Originating_Cost AS ALTLASTCOST
FROM      IV00103 V
                 LEFT OUTER JOIN IV00103 OV
                        ON V.ITEMNMBR = OV.ITEMNMBR
                        AND V.VENDORID <> OV.VENDORID
WHERE    V.VENDORID = @VENDORID AND V.LSTORDDT>'01/01/1901' AND OV.VENDORID IS NOT NULL AND OV.LSTORDDT>'01/01/1901'
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros