--locations_qaqc_report
select
   case when instr(ml.mloc_id, ',') > 0 then
      '"' || ml.mloc_id  || '"'
   else
      ml.mloc_id
   end MonitoringLocationIdentifier,
   case when instr(ml.mloc_name, ',') > 0 then
      '"' || ml.mloc_name || '"'
   else
      ml.mloc_name
   end MonitoringLocationName,
   case when instr(mltyp.mltyp_name, ',') > 0 then
      '"' || mltyp.mltyp_name || '"'
   else
      mltyp.mltyp_name
   end  MonitoringLocationType,
   ml.mloc_latitude Latitude,
   ml.mloc_longitude Longitude,
   to_char(ml.mloc_last_change_date, 'mm/dd/yyyy') last_change_date,
   ml.mloc_trans_id transaction_id,         
   case when instr(cu.cntry_name, ',') > 0 then
      '"' || cu.cntry_name  || '"'
   else
      cu.cntry_name
   end  Country,
   s.st_name State,
   c.cnty_name County,
   ml.mloc_huc_8 HUCEightDigitCode,
   nvl(to_char(latscaled),'N/A '||round(trunc(mloc_latitude,4),3)) geo_latscaled,
   nvl(to_char(longscaled),'N/A '||round(trunc(mloc_longitude,4),3)) geo_longscaled,
   COUNTRY GEO_COUNTRY,
   STATE GEO_STATE,
   COUNTY GEO_COUNTY,
   WBD_HUC12 GEO_HUCTWELVEDIGITCODE,
   REACHCODE GEO_REACHCODE,
   case when mloc_longitude=abs(mloc_longitude) then 'Y' else 'N' end as InvalidUSALatLong,
   dups.DuplicateInfo as DuplicateSiteOrg,       
   natdups.DuplicateInfo as NationalSiteDups,       
   case when length(trunc(mloc_latitude)-trunc(mloc_latitude,4))<4 or length(trunc(mloc_longitude)-trunc(mloc_longitude,4))<4 then 'Y' else 'N' end as  Less3DigitDecimal,          
   case when qlv.cntry_uid = ml.cntry_uid then 'N' else 'Y' end as  CountryDISAGREEwLatlong,
   case when qlv.st_uid = ml.st_uid then 'N' else 'Y' end as  StateDISAGREEwLatlong,
   case when qlv.cnty_uid = ml.cnty_uid then 'N' else 'Y' end as  CountyDISAGREEwLatlong,
   case when instr(NOTES_RECOMMENDATION, ',') > 0 then
      '"' || NOTES_RECOMMENDATION  || '"'
   else
      NOTES_RECOMMENDATION
   end NOTES_RECOMMENDATION  
from monitoring_location ml
...
order by ml.mloc_id;
      
--**************************************************************************************************************    
--results_qaqc_report
select
  case when instr(a.act_id, ',') > 0 then
  '"' || a.act_id || '"'
  else
    a.act_id
  end ActivityIdentifier,
  to_char(a.act_start_date, 'mm-dd-yyyy') ActivityStartDate,
  case when instr(at.actyp_cd, ',') > 0 then
  '"' || at.actyp_cd || '"'
  else
    at.actyp_cd
  end ActivityType,
  am.acmed_name ActivityMediaName,
  case when instr(ml.mloc_id, ',') > 0 then
  '"' || ml.mloc_id || '"'
  else
    ml.mloc_id
  end MonitoringLocationIdentifier,
  -- presently no commas found in result_detection_condition
  -- but, it does get updated from time to time
  case when instr(rdc.rdcnd_name, ',') > 0 then
  '"' || rdc.rdcnd_name || '"'
  else
    rdc.rdcnd_name
  end ResultDetectionConditionText,
  case when instr(c.chr_name, ',') > 0 then
  '"' || c.chr_name || '"'
  else
    c.chr_name
  end CharacteristicName,
  case when instr(sf.smfrc_name, ',') > 0 then
  '"' || sf.smfrc_name || '"'
  else
    sf.smfrc_name
  end ResultSampleFractionText,
  ms.mthspc_name ResultMethodSpeciationText,
  case when instr(r.res_measure, ',') > 0 then
  '"' || r.res_measure || '"'
  else
    r.res_measure
  end ResultMeasureValue,
  mu.msunt_cd ResultMeasureUnitCode,
  rs.ressta_name ResultStatusIdentifier,
  r.res_depth_height||' '||md.msunt_cd ResultDepthHeightMeasure,
 rsb.rsbas_cd StatisticalBaseCode,
  case when instr(am.anlmth_id, ',') > 0 then
  '"' || am.anlmth_id || '"'
  else
    am.anlmth_id
  end AnalyticalMethodIdentifier,
  amc.amctx_cd AnalyticalMethodIDContext,
  to_char(r.res_last_change_date, 'mm-dd-yyyy') last_change_date,
  a.act_trans_id transaction_id,
  case when c.chr_uid is Null then 'Y' else 'N' end as  Invalid_CharacteristicName_YN,
  case when qcvU.domain_status='Rejected' or qcvU.domain_status='Y' then 'Y' else 'N' end as  Invalid_Unit_YN,                                                                                                                                                                       
  case when qcvS.domain_status='Rejected' or qcvS.domain_status='Y' then 'Y' else 'N' end as  Invalid_Speciation_YN,                                                                                                                   
  case when qcvF.domain_status='Rejected' or qcvF.domain_status='Y' then 'Y' else 'N' end as  Invalid_Fraction_YN,                                                                                                                                                                       
  case when qcvM.domain_status='Rejected' or qcvM.domain_status='Y' then 'Y' else 'N' end as  Uncommon_Analytical_Method_YN,
  case when substr(r.res_measure,1,1) in ('<','>','~','@') then 'Y' else 'N' end as  Result_Special_Characters_YN,
  nvl(QAPP,'Y') as QAPP_NOTApproved_YN,
--    'N' QAPP_NOTApproved_YN,
  nvl(QAPP_DOC,'Y') as QAPP_Doc_Missing,
--    'N' QAPP_Doc_Missing,
  case when r.res_measure_converted < qcvU.min_value then 'Y' else 'N' end as  Below_Lower_Threshold_YN,
  case when r.res_measure_converted > qcvU.max_value then 'Y' else 'N' end as  Exceeds_Upper_Threshold_YN,
  qcvU.MIN_VALUE LowerRange,
  qcvU.MAX_VALUE UpperRange,
  qcvU.VALUE_UNIT TargetUnitRange,
  qcvU.CONVERSION_FACTOR UnitConversionFactor,
  qcvU.conversion_coefficient UnitConversionCoefficient,
  case when instr(qcvU.NOTES_RECOMMENDATION, ',') > 0 then
  '"' || qcvU.NOTES_RECOMMENDATION || '"'
  else
    qcvU.NOTES_RECOMMENDATION
  end NOTES_RECOMMENDATION
from activity a
...
order by a.act_id
;
