How to return sets of values based on condition in SQL Server 2005?

I am a beginner in SQL Server 2005 stored procedure. I can't seem to get it working as wanted.

I have a sp that takes in parameter @caseid from a table called annot. @caseid is assigned to value of column src_caseid and can have multiple references (ref_caseid) or none in table annot. I want to set a condition and set proper shepardsflag depending on the column court from table case which I did using INNER JOIN.

if @court is not NULL begin if @courtfc > 0 begin if exists(select a.ref_caseid, b.court, a.annotation, a.src_caseid from cba_annot a inner join cbm_case b on a.ref_caseid = b.caseid) begin if exists(select src_caseid from cba_annot where (annotation like '%Refd%' or annotation like '%Comp%') and src_caseid = @caseid) set @Shep = 4

if exists(select src_caseid from cba_annot where (annotation like '%Foll%' or annotation like '%Aff%') and src_caseid = @caseid) set @ShepFC = 3