c# - (db) Add another syntax in WHERE/SET(UPDATE) part? -
overview: code student can sign courses want read. he should accepted 1 course, not more(this got problem with). although student can search 3 courses @ same time priority selection 1-3.
if courses full students queue-index, starting 1 , up. once there's free spot in course(that's syntax below being used, looping each free spot in course), student queue-index 1 hit 0 , he's accepted course.
cmd.commandtext = "update [register] set queueindex = queueindex - 1, accepted = iif(queueindex = 1, 1, 0) queueindex > 0 , courseid = @cid;";
however don't know how improve syntax , implement checker in syntax if student accepted in other courses. if is, should not accepted(and set queue-index 0 he's no longer in queue, , accepted still false) , check next student instead. don't know how improve syntax.
in db-table, i'm using courseid, studentid, accepted(bool), selection(for 1-3 course choices, not important here), queueindex(int)
i implement kind of.. if current student queueindex = 1, , if of his/studentid choices/selections accepted = true queueindex = 0 , set accepted = false, current choice no longer relevant since he's accepted.
or and (if (studentid queueindex= 1 have (accepted=true) in choices/courseid)) = false
in where? syntax in part or something.
edit: thinking in where
-part
and 0 = (select count(accepted) [register] studentid = (select studentid [register] queueindex = 1 , courseid = @cid)) , accepted = true
edit2: ctumturk made me realize asked wrong question. should set student queueindex = 0
course she/he selected once accepted.
Comments
Post a Comment