cursor.execute(f"SELECT '{config['instance']}' as instance, kols.npi_num,kols.id,CONCAT_WS('',kols.first_name,kols.middle_name,kols.last_name) as kol_name, projects.name as project_name, clients.name as client_name,CONCAT(client_users.first_name,'',client_users.last_name) as user_name, GROUP_CONCAT(DISTINCT log_activities.transaction_name,':',date(log_activities.created_on)) as project_details,case when user_kols.opt_in_out_status = 3 then 'Opted Out' when user_kols.opt_in_out_status = 4 then 'Opted In' else '' end as status , date(kols.data_updated) as data_processed_date,countries.Country as user_country,CONCAT(poc.first_name,'',poc.last_name) as client_poc FROM kols left join user_kols on user_kols.kol_id = kols.id left join countries on countries.CountryId = kols.country_id inner join opt_inout_statuses on opt_inout_statuses.id = user_kols.opt_in_out_status left join log_activities on log_activities.miscellaneous1 = user_kols.kol_id left join client_users on client_users.id = user_kols.user_id left join clients on client_users.client_id = clients.id left join client_users as poc on poc.id = clients.created_by left join project_clients on project_clients.client_id = clients.id left join projects on project_clients.project_id = projects.id where log_activities.module ='opt_in_out' and log_activities.transaction_name in ('New','Opt-in Requested','Opt-out','Opt-in Approved','Opt-in Expired','Opt-in Received','Opt-in') group by kols.id;")