We help IT Professionals succeed at work.
Get Started

SQL IF structure...would like to convert to Case Statement

JoshuaRyan
JoshuaRyan asked
on
310 Views
Last Modified: 2010-05-18
Hello,
I have an If structure and I'm curious if there is a way I could convert this to a Case statement or perhaps someone has suggestions on a more efficient method.  The current process is very slow.
See below:
If @@rowcount = 0      
begin      
    select @row_count = 0      
end      
       
If @status_type = 1      
begin      
    update ORS_RPMS set awl_count = @row_count where employee_id = @employee_id and last_update_date = @dte    
return
end      
     
If @status_type = 2      
begin      
update ORS_RPMS set warr_count = @row_count where employee_id = @employee_id and last_update_date = @dte      
return
end        
       
If @status_type = 3      
begin      
    update ORS_RPMS set dsch_count = @row_count where employee_id = @employee_id and last_update_date = @dte      
return
end        
       
If @status_type = 4      
begin      
    update ORS_RPMS set parole_count = @row_count where employee_id = @employee_id and last_update_date = @dte      
return
end        
       
If @status_type = 5      
begin      
    update ORS_RPMS set cbop_count = @row_count where employee_id = @employee_id and last_update_date = @dte      
return
end        
     
If @status_type = 6      
begin      
    update ORS_RPMS set inst_count = @row_count where employee_id = @employee_id and last_update_date = @dte      
return
end        
       
If @status_type = 7      
begin      
   update ORS_RPMS set aol_count = @row_count where employee_id = @employee_id and last_update_date = @dte      
return
end        
     
If @status_type = 8  
begin      
  update ORS_RPMS set awol_count = @row_count where employee_id = @employee_id and last_update_date = @dte      
return
end        
     
If @status_type = 9      
begin      
    update ORS_RPMS set afp_count = @row_count where employee_id =@employee_id and last_update_date = @dte      
return
end        
     
If @status_type = 10      
begin      
    update ORS_RPMS set tarr_count = @row_count where employee_id = @employee_id and last_update_date = @dte      
return
end        
     
If @status_type= 11    
begin      
    update ORS_RPMS set rev_count = @row_count where employee_id = @employee_id and last_update_date = @dte      
return
end      
     
If @status_type = 12      
begin      
    update ORS_RPMS set parr_count = @row_count where employee_id = @employee_id and last_update_date = @dte      
return
end        
     
If @status_type = 13      
begin      
    update ORS_RPMS set guest_count = @row_count where employee_id = @employee_id and last_update_date = @dte      
return
end        
     
If @status_type = 14      
begin      
    update ORS_RPMS set conf_count = @row_count where employee_id = @employee_id and last_update_date = @dte      
return
end      
Comment
Watch Question
This problem has been solved!
Unlock 5 Answers and 16 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE