You are asking for dynamic SQL in a stored procedure, which doesn't exist. Someone else recently posted a process whereby they formatted the statment and then shelled out (using SYSTEM) to dbaccess for execution, but that's not dynamic sql, nor does it execute within the same transaction and can in fact deadlock with itself because it's a new SID.