 SELECT NULL AS concept_id,
 	CASE -- add [brandname] if proprietaryname exists and not identical to nonproprietaryname
 		WHEN brand_name IS NULL
-			THEN SUBSTR(TRIM(concept_name), 1, 255)
-		ELSE SUBSTR(CONCAT (
+			THEN TRIM(SUBSTR(TRIM(concept_name), 1, 255))
+		ELSE TRIM(SUBSTR(CONCAT (
 					TRIM(concept_name),
 					' [',
 					brand_name,
 					']'
-					), 1, 255)
+					), 1, 255))
 		END AS concept_name,
 	'Drug' AS domain_id,
 	'NDC' AS vocabulary_id,

				CASE 
					WHEN MULTI_NONPROPRIETARYNAME IS NULL
						THEN CONCAT (
								substr(nonproprietaryname, 1, 100),
								CASE 
									WHEN length(nonproprietaryname) > 100
										THEN '...'
									END,
								NULLIF(' ' || substr(aggr_dose, 1, 100), ' '),
								' ',
								substr(routename, 1, 100),
								' ',
								substr(dosageformname, 1, 100)
								)
					ELSE CONCAT (
							'Multiple formulations: ',
							substr(nonproprietaryname, 1, 100),
							CASE 
								WHEN length(nonproprietaryname) > 100
									THEN '...'
								END,
							NULLIF(' ' || substr(aggr_dose, 1, 100), ' '),
							' ',
							substr(routename, 1, 100),
							' ',
							substr(dosageformname, 1, 100)
							)
					END AS concept_name,
				SUBSTR(brand_name, 1, 255) AS brand_name,

	valid_end_date,
	invalid_reason
	)
SELECT TRIM(SUBSTR(concept_name, 1, 255)) concept_name,
	CASE 
		WHEN displayname IN (
				'COSMETIC',
