Solved

SQL Query Help...

Posted on 2011-03-16
3
258 Views
Last Modified: 2012-05-11
Havin a brain fart here...  I need to get the c.catID in this query, how can I do that?


Select d.catID, d.catName, 

1

From vwSelectPartCategory d
Where d.catID In (Select a.parentID From vwSelectPartCategory a 
Where a.catID In(Select b.parentID From vwSelectPartCategory b 
Where b.catID In (Select c.catID From vwSelectPart c 
Where c.partMake Like '%VW%' And 
c.partModel Like '%Jetta%')));

Open in new window

0
Comment
Question by:kevp75
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 450 total points
ID: 35151807
hmmm

Select d.catID, d.catName, 1, c.CatID
From vwSelectPartCategory d
JOIN vwSelectPartCategory a
  ON a.ParentID = d.CatID
JOIN vwSelectPartCategory b
  ON b.ParentID = a.catID
JOIN vwSelectPart c
  ON c.catID = b.CatID
 AND c.partMake Like '%VW%' 
 And c.partModel Like '%Jetta%'

Open in new window

0
 
LVL 40

Assisted Solution

by:Sharath
Sharath earned 50 total points
ID: 35151890
use DISTINCT key word, if you have multiple records returned because of JOIN conditions.
SELECT DISTINCT d.catID, 
                d.catName, 
                1, 
                c.CatID 
  FROM vwSelectPartCategory d 
       JOIN vwSelectPartCategory a 
         ON a.ParentID = d.CatID 
       JOIN vwSelectPartCategory b 
         ON b.ParentID = a.catID 
       JOIN vwSelectPart c 
         ON c.catID = b.CatID 
            AND c.partMake LIKE '%VW%' 
            AND c.partModel LIKE '%Jetta%'

Open in new window

0
 
LVL 25

Author Closing Comment

by:kevp75
ID: 35151971
sweet.  thanks guys
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now