 			[resulted_on]
 		FROM
 			(
-				SELECT id,
+			SELECT id,
 				patient_id,
 				snp_id,
 				[1] AS value1,

				[4] AS [resulted_on]
			FROM
			(
				SELECT snps.patient_id, snps.id, snps.attribute_id AS [snp_id], CONVERT(VARCHAR, res_dt.value_date_time, 101) AS [value_short_text],
					4 AS RowNum
				FROM [mhgr_eav].[dbo].[result_entities] snps
				INNER JOIN [mhgr_eav].[dbo].[result_entities] res_dt ON res_dt.parent_id = snps.id 
					AND res_dt.attribute_id = 72 -- Resulted on
				INNER JOIN [mhgr_eav].[dbo].[attribute_relationships] ar ON snps.attribute_id = ar.attribute1_id
					AND ar.relationship_id = 5
					AND ar.attribute2_id = 31      -- CYP2C19
				WHERE snps.parent_id IS NULL

				UNION ALL

				SELECT snps.patient_id, snps.id, snps.attribute_id AS [snp_id], refs.value_short_text,
					3 AS RowNum
				FROM [mhgr_eav].[dbo].[result_entities] snps
				INNER JOIN [mhgr_eav].[dbo].[result_entities] refs ON refs.parent_id = snps.id 
					AND refs.attribute_id = 115 -- Reference bases
				INNER JOIN [mhgr_eav].[dbo].[attribute_relationships] ar ON snps.attribute_id = ar.attribute1_id
					AND ar.relationship_id = 5     -- Variant of gene
					AND ar.attribute2_id = 31      -- CYP2C19
				WHERE snps.parent_id IS NULL

				UNION ALL

				[4] AS resulted_on
			FROM
			(
				-- Grab resulted on date
				SELECT features.patient_id, features.id, snps.attribute_id AS [snp_id], CONVERT(VARCHAR, res_dt.value_date_time, 101) AS [value_short_text],
					4 AS RowNum
				FROM  [mhgr_eav].[dbo].[result_entities] features
				INNER JOIN  [mhgr_eav].[dbo].[result_entities] vcf ON vcf.id = features.parent_id
					AND vcf.attribute_id = 103		-- VCF result
				INNER JOIN  [mhgr_eav].[dbo].[result_entities] res_dt ON res_dt.parent_id = vcf.id 
					AND res_dt.attribute_id = 72	-- Reference bases
				INNER JOIN  [mhgr_eav].[dbo].[result_entities] snps ON snps.parent_id = features.id
				INNER JOIN  [mhgr_eav].[dbo].[attribute_relationships] ar ON snps.attribute_id = ar.attribute1_id
					AND ar.relationship_id = 5		-- Variant of gene
