Click here to Skip to main content
16,011,626 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends
the below is my join query for getting some result

SQL
create procedure sp_bindexamclass(@classid int,@examid int)
as
begin
select en.ExamName,St.Standered_name,Sr.SubjectName,ec.Maximummark,ec.Minimummark from Standered_details St inner join ExamClasssetting_details ec on St.Standered_id=ec.Classid inner join SubjectRegistration_details Sr on Sr.SubjectCode=ec.subjectid inner join ExamNameSetting_details en on en.ExamId=ec.ExamId where ec.Classid=@classid and ec.ExamId=@examid

end





Table relation is

1.standered details
relational key is
standered_id
to
classid
(fk) of Examclasssetting_details
2.SubjectRegistration_details
relational key is
subjectcode
to
subjectid
of
Examclasssetting_details
3 .ExamNamesetting_details
relational key is
ExamId
to
ExamId
of Examclasssetting_deatails

all the table contains data for join query. but i couldnt get the desired result. what is the problem in join query.
Posted
Updated 8-Dec-12 0:33am
v2

1 solution

create procedure sp_bindexamclass(@classid int,@examid int)
as
begin
select en.ExamName,St.Standered_name,Sr.SubjectName,ec.Maximummark,ec.Minimummark
from Standered_details St
inner join ExamClasssetting_details ec on ec.Classid =St.Standered_id and ec.Classid=@classid and ec.ExamId=@examid
inner join SubjectRegistration_details Sr on ec.subjectid =Sr.SubjectCode
inner join ExamNameSetting_details en on en.ExamId=ec.ExamId
end


Try This one.

Note:Where we create join at that time on clause work as where class for that given table so keep all the condition related to that table after on.

If you use any join then where condition is for first table for eg. in this join Standered_details condition you can write in where clause.
 
Share this answer
 
v3
Comments
baskaran chellasamy 10-Dec-12 1:02am    
sorry. i tried the way that you speicfy.but i didnt get result. and also change the query like this
ALTER procedure [dbo].[sp_bindexamclass](@classid int,@examid int)
as
begin
select en.ExamName,St.Standered_name,Sr.SubjectName,ec.Maximummark,ec.Minimummark from ExamClasssetting_details ec inner join Standered_details St on ec.Classid=St.Standered_id inner join SubjectRegistration_details Sr on ec.subjectid=Sr.SubjectCode inner join ExamNameSetting_details en on en.ExamId=ec.ExamId where ec.Classid=@classid and ec.ExamId=@examid

end

but still it does not giving a result.

Patel Shailendra 10-Dec-12 5:55am    
if possible then show the table with dummy recode. possibly i will solve your problem.

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