SELECT PERIODO, NUM_RUC
   FROM (
	   SELECT DISTINCT '202404' PERIODO, NUM_RUC
	   FROM  ODS.MM_GESCOM_UNIVERSO_MERCADO_TOTAL_BPE
	   WHERE LEN(NUM_RUC) = 11
	   UNION
	   SELECT DISTINCT '202404' PERIODO, RUC NUM_RUC
	   FROM TMP_BBC_UNIVERSO_PERUFARMA
	   UNION
	   SELECT DISTINCT '202404' PERIODO, RUC NUM_RUC
	   FROM TMP_BBC_UNIVERSO_QUIMICA_SUIZA
	   UNION
	   SELECT DISTINCT '202404' PERIODO, RUC NUM_RUC
	   FROM ODS.HM_GESCOM_EFACT_VENTAS
	   UNION
	   SELECT DISTINCT '202404' PERIODO, NUM_RUC
	   FROM ODS.HM_EC_VENTAS_IZIPAY
	   UNION
	   SELECT DISTINCT '202404' PERIODO, RUC NUM_RUC
	   FROM TMP_BBC_HUBS_EVALUAR_RIESGOS
   ) AA
   GROUP BY PERIODO, NUM_RUC

Add a code snippet to your website: www.paste.org