How to set a session id to a value after using a case-when statement?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Charles Ndethi
    New Member
    • Jan 2011
    • 10

    How to set a session id to a value after using a case-when statement?

    Hi I want to set the session id to a value after evaluating the request_time using a case when statement.

    here 's the table
    Code:
    userinput_id         session_id          request_time               keyword
         1                                   2011-03-04 08:23:45        free    
         2                                   2011-03-04 08:25:50        free
    when the keyword is entered request_time ( TIMESTAMP) is stored automatically , I also want to set the session id automatically after evaluating the request_time in a case when statement:

    Code:
    create procedure upd_userinput(in request_time TIMESTAMP,out time TIME, out user_session_id INT)     
    begin      
    set time = time(request_time);    
    case  
    when time < '09:15:00' && time > '08:15:00' then      
    set user_session_id = 1; 
    
    when time < '10:15:00' && time > '09:15:00' then
    set user_session_id = 2;  
    
    when time < '11:15:00' && time > '10:15:00' then
    set user_session_id = 3;
    
    when time < '12:15:00' && time > '11:15:00' then
    set user_session_id = 4;
    
    when time < '13:15:00' && time > '12:15:00' then
    set user_session_id = 5;
    
    when time < '14:15:00' && time > '13:15:00' then
    set user_session_id = 6;
    
    when time < '15:15:00' && time > '14:15:00' then
    set user_session_id = 7;
    
    when time < '16:15:00' && time > '15:15:00' then
    set user_session_id = 8;
    
    when time < '17:15:00' && time > '16:15:00' then
    set user_session_id = 9;
    
    when time < '18:15:00' && time > '17:15:00' then
    set user_session_id = 10;
    
    when time < '19:15:00' && time > '18:15:00' then
    set user_session_id = 11;
    
    when time < '20:15:00' && time > '19:15:00' then
    set user_session_id = 12;
    
    else set user_session_id = 0;
    
    end case;  
    end //
    The procedure executes.(it returns OK, 0 rows affected) on mysql terminal. but when i call it (it calls fine again) and check the table nothing has changed, is it because i use set rather than insert or what could be the problem? Is there an easier way?

    Thanks. Please help.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    An update SQL is of the form:
    Code:
    UPDATE TableName SET FieldName1 = Value, FieldName2=Value

    Comment

    Working...