Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
USE [cms]
GO
/****** Object:  StoredProcedure [dbo].[SpGetRelatedProducts]    Script Date: 10/10/2012 23:55:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[SpGetRelatedProducts](@pid int)
AS
select *
from product join subcategory on subcategory.subcate_id=category.cate_id
where product.subcate_id in (
                              select subcate_id 
                              from product 
                              where pid = @pid
                            )



i want that all the products, which belong from different subcategory and these subcategories belongs from same category and also the columns of the subcategory table, thats why i used above join, but there is something wrong in the query.
Posted
Comments
Zoltán Zörgő 10-Oct-12 15:36pm    
Although I don't really got your intentions - I can not see, that you join the category table, but you use it in the join condition.
Rohit Shrivastava 10-Oct-12 18:46pm    
There should be a reference of category table? Do you have one. Please provide the tables and relationships. Is input parameter product id?
damodara naidu betha 11-Oct-12 2:03am    
Can you post what is the result coming and what should be the desired out put along with input data?

1 solution

change
SQL
from product join subcategory on subcategory.subcate_id=category.cate_id

to
SQL
from product join subcategory on subcategory.subcate_id=product.subcate_id

and remove your where clause and replace it with:
SQL
where pid = @pid
 
Share this answer
 
Comments
damodara naidu betha 15-Oct-12 2:35am    
My 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900