Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please Help me to Write/construct this query?

Status
Not open for further replies.

happyIndian100

Programmer
Jul 20, 2003
66
US
Please Help!
I have two tables named category and Products which has the following data:-

category :
-----------
catid ParentCode CatCode
-----------------------------
1 IT CATIT
2 IT ABCIT
3 IT HPIT
4 PRN COMPRN
5 CDD SRRCD

Products:
--------
ID CatCodeDet
-----------------
1001 1-CATIT
1002 3-HPIT
1003 5-SRRCD
1004 4-COMPRN
1005 3-HPIT

now i want all the Products where parentcode is IT.
the result should be like:

ID CatCodeDet
-----------------
1001 1-CATIT
1002 3-HPIT
1005 3-HPIT

Please help.

Thx in advance...

 
SELECT [ID],CatCodeDet
FROM PRODUCTS
WHERE LEFT(CatCodeDet,1) IN
(SELECT catid from category where ParentCode = 'IT')

DBomrrsm
 
Thank You very much DBomrrsm.
It was perfect.

i made a bit of change if the catCodeDet is 2 or more digits infront like (150-HPIT or 25-HPIT).

so i used,
substring(CatCodeDet,1,patindex('%-%',CatCodeDet)-1) in place of LEFT(CatCodeDet,1).

thx once again.
Have a Nice Day.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top