I am saying that it needs to be done in your application and not inside the stored procedure. Stored procedures should be used for data access and not to do things that an application is designed to do.