sql server 2008 - Scalar function-Merge -


i have scalar function written 3 times minor change. m planning merge 3 functions 1 function.

forstudent- declare @cn int select @cn=count(*) xyz a.subjects in ('1223','2234','3345')  if @cnt>3        select @pass=1       else        select @pass=0   return @pass end     //similarly forstudent - b      declare @cn int         select @cn=count(*)         xyz         a.subjects in ('1214','0987','0098')          if @cnt>5               select @pass=1               else                select @pass=0           return @pass         end 

same student 3.

for instance there 3 students (fixed value=3), , have fixed sujects. how can merge these 3 functions one?

i presently doing if @student= 'a' begin call code end if @student = 'b' begin call code b end if @student = 'c' call code c end 

is there better solution can think of? thanks,

the obvious way have studentsubjects table (possibly indication it's use function, or using existing such table 3 special subjects can marked in way)

create table studentsubjects (     studentid char(1) not null,     subject char(4) not null ) 

(you'll have 3 rows each student, each subject stored separately)

and function be:

select @cn=count(*) xyz a.subjects in (select subject studentsubjects studentid=@studentid) 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -