Click here to Skip to main content
15,905,566 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi here is my sp to get details from two tables

SQL
create PROCEDURE [dbo].[usp_GetCategoryByID1]
@ID int
AS BEGIN
select  tblCategory.*,tblContractType.*
From tblCategory left outer join tblContractType on tblCategory.catContractTypeID=tblContractType.cttContractTypeID
 and tblContractType.cttisDelStatus='0'
where catID=@ID and tblCategory.catisDelStatus='0'
 END


and i want to alter this sp i want to add one more table to get details

tblCategorySub

and @ID=subcID..can any one suggest me how to join in this sp..

thanks
Posted

To alter your procedure use Alter keyword and how do we know your table structure and relation??

SQL
Alter PROCEDURE [dbo].[usp_GetCategoryByID1]
@ID int
AS BEGIN
--Write your sql query here..

select  tblCategory.*,tblContractType.*,tblCategorySub.*
From tblCategory left outer join tblContractType on tblCategory.catContractTypeID=tblContractType.cttContractTypeID 
--here I added (change your table name according to your table structure and relation)
inner join tblCategorySub on tblCategory.subcID= tblCategorySub.subcID
--upto here
 and tblContractType.cttisDelStatus='0'
where catID=@ID and tblCategory.catisDelStatus='0'

 END
 
Share this answer
 
v2
Comments
ythisbug 7-Jul-12 1:44am    
thanks..i mean to say i want to add one more table to join in that query tblCategorySub with subcID is column name..if any doubt..reply
Hi ..

Please try the below query .

SQL
Alter  PROCEDURE [dbo].[usp_GetCategoryByID1]
@ID int
AS BEGIN
select  tblCategory.*,tblContractType.*
From tblCategory left outer join tblContractType 
on tblCategory.catContractTypeID=tblContractType.cttContractTypeID
join tblCategorySub on tblCategorySub.subcID =tblCategory.catContractTypeID
 
and tblCategorySub.@ID=subcID
 and tblContractType.cttisDelStatus='0'
 
where catID=@ID and tblCategory.catisDelStatus='0'
 END
 
Share this answer
 
SQL
select  tblCategory.*,tblContractType.*
From tblCategory 
 left outer join tblContractType on (tblCategory.catContractTypeID=tblContractType.cttContractTypeID)

left outer join tblCategorySub  on 
(tblCategorySub.ID=tblCategory.subid)

where catID=@ID and tblCategory.catisDelStatus='0' and  tblContractType.cttisDelStatus='0'
 
Share this answer
 

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