Solved

SQL Query Help...

Posted on 2011-03-16
3
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 143

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 41

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ms sql and asp dates 5 40
connection to SQL 2012 error in windows 10 18 41
Sorting a SQL script 5 34
Section based report in SSRS 14 14
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…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

736 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