text: IF OBJECT_ID('@targetTable', 'U') IS NOT NULL DROP TABLE @targetTable;
  
  WITH CTE_VOCAB_1 AS (
  	SELECT *
  	FROM @stcmTable
  	WHERE UPPER(SOURCE_VOCABULARY_ID) = 'EUPLADR_TO_STANDARD'
  ),
  CTE_VOCAB_2 AS (
  	SELECT *
  	FROM @stcmTable
  	WHERE UPPER(SOURCE_VOCABULARY_ID) = 'MEDDRA_TO_STANDARD'
  )
  SELECT ID,
        SOURCE_ID,
        SOURCE_CODE_1,
        SOURCE_CODE_TYPE_1,
        SOURCE_CODE_NAME_1,
        CASE WHEN v1.TARGET_CONCEPT_ID IS NULL THEN 0 ELSE v1.TARGET_CONCEPT_ID END CONCEPT_ID_1,
        RELATIONSHIP_ID,
        SOURCE_CODE_2,
        SOURCE_CODE_TYPE_2,
        SOURCE_CODE_NAME_2,
        CASE WHEN v2.TARGET_CONCEPT_ID IS NULL THEN 0 ELSE v2.TARGET_CONCEPT_ID END CONCEPT_ID_2,
        UNIQUE_IDENTIFIER,
        UNIQUE_IDENTIFIER_TYPE,
        SOC,
        HLGT,
        HTL,
        LLT,
        AGE_GROUP,
        GENDER,
        CAUSALITY,
        FREQUENCY,
        CLASS_WARNING,
        CLINICAL_TRIALS,
        POST_MARKETING,
        COMMENT
  INTO @targetTable
  FROM @sourceTable eu
  	LEFT OUTER JOIN CTE_VOCAB_1 v1
  		ON eu.SOURCE_CODE_1 = v1.SOURCE_CODE
  	LEFT OUTER JOIN CTE_VOCAB_2 v2
  		ON eu.SOURCE_CODE_2 = v2.SOURCE_CODE;
  
  CREATE INDEX IDX_@id_CONCEPT_ID_1_CONCEPT_ID_2 ON @targetTable (CONCEPT_ID_1, CONCEPT_ID_2);
  
  ALTER TABLE @targetTable OWNER TO RW_GRP;
  