please help with the query..I want to have a conditional statement in where clause
depending on the result of select Count(*) statement
originally my query is:
select * from StudentMaster where StudentMaster.StudId = @pStudId and exists (select * from tblFinals where tblFinals.StudId=StudentMaster.StudId)
but just today,
I realize that user will have the option to select students either in tblFinals or in tblSemiFinals
so the condition will be:
if (select count(*) from tblStudentGrades where StudId=@pStudId and Remarks='Finals') > 0
then
select * from StudentMaster where StudentMaster.StudId = @pStudId and exists (select * from tblFinals where tblFinals.StudId=StudentMaster.StudId)
else
select * from StudentMaster where StudentMaster.StudId = @pStudId and exists (select * from tblFinals where tblSemiFinals.StudId=StudentMaster.StudId)
but i want the first part of the query to be permanent and will just change in where clause like this:
select * from StudentMaster where StudentMaster.StudId = @pStudId and
if (select count(*) from tblStudentGrades where StudId=StudentMaster.StudId and Remarks='Finals') > 0
then
exists (select * from tblFinals where tblFinals.StudId=StudentMaster.StudId)
else
exists (select * from tblFinals where tblSemiFinals.StudId=StudentMaster.StudId)
is this possible??thanks..