Click here to Skip to main content
15,314,303 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Studdet table as follows;
 Studid    StudName    Marks   QpName    Bthid  AnswerID

32468     VENKATA      70  SAC       625     10861
32468     VENKATA      88  REO       616     10715
44258      RAJ         100 AFF        71      1136
44258      RAJ         80  PSCRB      78      1241
44258      RAJ         80  MFA       100      1615
Answer table as follows;
Studid   Qno  AnswerID

 32468    4    10715
 32468    4    10861
 44258    4    1136
 44258    4    1241
Batch table as follows;
Bthno  Batch Date   Attender Class
     
      B09   12/10/2012       Rk     SAC
      B143  12/9/2012        RV     REO
Course Table as follows;
Course COde
    SAC
    RE0
Using the above tables, I want to get the following output:

I want to see the below output details for particular student id.

I want to write the query, in that I want to use parameter as student id and get the below output as follows;
CourseCode     Marks   Qpname   Qno    Bthno   BatchDate     Attender

 SAC            70      SAC      4     B09    12/10/2012      RK
 REO            88      REO      4     B09    12/10/2012      RV
Posted
Updated 30-Apr-13 20:22pm
v2
Comments
Prasad Khandekar 2-May-13 10:59am
   
Must be a duplicate of (http://www.codeproject.com/Questions/585700/howpluscanplusiplusgetplustheplusoutputplususingpl).

1 solution

SQL
--You can try the following Query it may help you


DECLARE @Student TABLE (Studid INT,StudName VARCHAR(50),Marks int,QpName VARCHAR(50),Bthid int,AnswerID INT)

INSERT  INTO @Student VALUES (32468,'VENKATA',70,'SAC',625,10861)
INSERT  INTO @Student VALUES ( 32468,'VENKATA',88,'REO',616,10715)
INSERT  INTO @Student VALUES (44258,'RAJ',100,'AFF',71,1136)
INSERT  INTO @Student VALUES (44258,'RAJ',80,'PSCRB',78,1241)
INSERT  INTO @Student VALUES (44258,'RAJ',80,'MFA',100,1615)

DECLARE @Answer TABLE (Studid INT,Qno int,AnswerID INT)

INSERT  INTO @Answer VALUES (32468,4,10715)
INSERT  INTO @Answer VALUES (32468,4,10861)
INSERT  INTO @Answer VALUES (44258,4,1136)
INSERT  INTO @Answer VALUES (44258,4,1241)

DECLARE @Batch TABLE (Bthno VARCHAR(50),BatchDate VARCHAR(50),Attender VARCHAR(50),Class VARCHAR(50))

INSERT  INTO @Batch VALUES ('B09','12/10/2012','Rk','SAC')
INSERT  INTO @Batch VALUES ('B143','12/9/2012','RV','REO')


DECLARE @Course TABLE (CourseCode VARCHAR(50))

INSERT  INTO @Course VALUES ('SAC')
INSERT  INTO @Course VALUES ('REO')

Select * From @Student
Select * From @Answer
Select * from @Batch

Select DISTINCT C.CourseCode,S.Marks,S.QpName,A.Qno,B.Bthno,B.BatchDate,B.Attender from @Course C
JOIN    @Batch      B   ON  B.Class=C.CourseCode
JOIN    @Student    S   ON  S.QpName=C.CourseCode
JOIN    @Answer     A   ON  A.Studid=S.Studid
   
Comments
Maciej Los 14-May-13 8:46am
   
+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