Help with SQL Procedure Query
Posted on 2011-02-13
I have a table with few columns and my questions related to the 2 columns only.
let me say
As you see the table stores the student_id as -1 when the audience_id is 2
I have the following query
SELECT * FROM <TableNAME>
(CLASS_ID IN (SELECT CLASS_ID FROM STUDENT_MANAGEMENT_REGISTRATION) ) AND
(STUDENT_ID=@STUDENT_ID OR @STUDENT_ID=-1 )
Now what i need to do is built a query that retrieve records based on the condition clause.
i wish to retrieve records pertaining to the student_id passed in the parameter
Say , the value is -1 then i am getting the relevant results.
Now, the value of @STUDENT_ID=1,then i am getting the relevant results but only partial
let me explain further. When @STUDENT_ID=1 , i would need all the results where there is a match for student_id=1 aswells as the records
that pertain to the class_id =10 where audience_id=2.
Finally if i pass @STUDENT_ID=2, which is not found the illustration of records above, the records should be retrieved the top 2 records in the
illustration needs to be retrieved if the audience_id=2 and clas_id=10
In short how can i change the where clause conditions to ensure i get the results.