• Thanks Sean

    I rewrote the stored procedure eliminating the sp_ prefix in the call to another procedure, regarding the function calls do not quite understand you want to tell me, is better than all code functions (actually functions only execute a query and return one result) write it in the process?

    On the other hand (and this was the reason for my first post), the structure of the procedure okay ?, I think so much begin end makes the code may not run properly.