Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jonekim
Starting Member
35 Posts |
Posted - 2012-01-30 : 11:16:37
|
| I am using MS SQL SERVER2005 & c#I have designed a database having tables:STUDENT table(STUDENT_ID(PK),STUDENT_NAME)STUDENT_ID = 1 STUDENT_NAME = SN1STUDENT_ID = 2 STUDENT_NAME = SN2STUDENT_ID = 3 STUDENT_NAME = SN3COURSE table(COURSE_CODE(PK), COURSE_NAME)COURSE_CODE = CC1 COURSE_NAME = CN1COURSE_CODE = CC2 COURSE_NAME = CN2COURSE_CODE = CC3 COURSE_NAME = CN3##STUDENT table & COURSE table exhibits many-to-many relationCLASS table ##junction table(CLASS_GRADE, STUDENT_ID, COURSE_CODE)CLASS_GRADE = 1 STUDENT_ID = 1 COURSE_CODE = CC1CLASS_GRADE = 2 STUDENT_ID = 2 COURSE_CODE = CC2CLASS_GRADE = 3 STUDENT_ID = 3 COURSE_CODE = CC3Now I want a table showing the name of the students and the course taught in an individual class.User is asked to enter the class_grade and according to the user input, list of the students enrolled for that class and the course taught in that class should be displayed.How to take user input in sql query? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-30 : 11:30:55
|
you need to make a stored procedure for that with a parameter for passing grade value. then use parameter to filter and display the resultssomething likeCREATE PROC GetClassData@Class_Grade intASSELECTFROM CLASS cINNER JOIN STUDENT sON s.STUDENT_ID = c.STUDENT_IDINNER JOIN COURSE crON cr.COURSE_CODE = s.COURSE_CODE WHERE c.CLASS_GRADE = @Class_Grade GOcreate the procedure and then use it likeEXEC GetClassData @Class_Grade = 1EXEC GetClassData @Class_Grade = 2EXEC GetClassData @Class_Grade = 3 etc ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|