 			(
 			SELECT concept_code,
 				concept_class_id,
-				MULTI_NONPROPRIETARYNAME,
 				CASE 
-					WHEN MULTI_NONPROPRIETARYNAME IS NULL
+					WHEN multi_nonproprietaryname IS NULL
 						THEN CONCAT (
 								SUBSTR(nonproprietaryname, 1, 100),
 								CASE 
-									WHEN length(nonproprietaryname) > 100
+									WHEN LENGTH(nonproprietaryname) > 100
 										THEN '...'
 									END,
-								NULLIF(' ' || SUBSTR(aggr_dose, 1, 100), ' '),
+								' ' || TRIM(SUBSTR(aggr_dose, 1, 100)),
+								' ' || TRIM(SUBSTR(routename, 1, 100)),
 								' ',
-								SUBSTR(routename, 1, 100),
-								' ',
-								SUBSTR(dosageformname, 1, 100)
+								TRIM(SUBSTR(dosageformname, 1, 100))
 								)
 					ELSE CONCAT (
 							'Multiple formulations: ',
 							SUBSTR(nonproprietaryname, 1, 100),
 							CASE 
-								WHEN length(nonproprietaryname) > 100
+								WHEN LENGTH(nonproprietaryname) > 100
 									THEN '...'
 								END,
-							NULLIF(' ' || SUBSTR(aggr_dose, 1, 100), ' '),
+							' ' || TRIM(SUBSTR(aggr_dose, 1, 100)),
+							' ' || TRIM(SUBSTR(routename, 1, 100)),
 							' ',
-							SUBSTR(routename, 1, 100),
-							' ',
-							SUBSTR(dosageformname, 1, 100)
+							TRIM(SUBSTR(dosageformname, 1, 100))
 							)
 					END AS concept_name,
 				SUBSTR(brand_name, 1, 255) AS brand_name,

	JOIN vocabulary v ON v.vocabulary_id = 'NDC'
	) AS s0;

--22. Add additional mapping for NDC codes 
--The 9-digit NDC codes that have no mapping can be mapped to the same concept of the 11-digit NDC codes, if all 11-digit NDC codes agree on the same destination Concept

CREATE INDEX IF NOT EXISTS trgm_idx ON concept_stage USING GIN (concept_code devv5.gin_trgm_ops); --for LIKE patterns

	AND NOT EXISTS (
		SELECT 1
		FROM concept_stage cs_int
		WHERE LOWER(s.concept_code) = LOWER(cs_int.concept_code)
		);

--6. Load other SPL into concept_stage (from 'product')
