Solved

SQL Query Help...

Posted on 2011-03-16
3
257 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
Comment Utility
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
Comment Utility
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
Comment Utility
sweet.  thanks guys
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

763 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

9 Experts available now in Live!

Get 1:1 Help Now