 				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 dbo.result_entities features
-				INNER JOIN dbo.result_entities vcf ON vcf.id = features.parent_id
-					AND vcf.attribute_id = 103		-- VCF result
-				INNER JOIN dbo.result_entities res_dt ON res_dt.parent_id = vcf.id 
+				INNER JOIN dbo.result_entities gvf ON gvf.id = features.parent_id
+					AND gvf.attribute_id = 74  -- GVF result
+				INNER JOIN dbo.result_entities res_dt ON res_dt.parent_id = gvf.id 
 					AND res_dt.attribute_id = 72 -- Reference bases
 				INNER JOIN dbo.result_entities snps ON snps.parent_id = features.id
-				INNER JOIN dbo.attribute_relationships ar ON snps.attribute_id = ar.attribute1_id
-					AND ar.relationship_id = 5		-- Variant of gene
-					AND ar.attribute2_id = 32		-- CYP2C9
+				INNER JOIN dbo.attribute_relationships ar ON snps.attribute_id = ar.attribute1_id AND ar.relationship_id = 5
+					AND ar.attribute2_id = 32      -- CYP2C9
 				INNER JOIN dbo.patients p ON p.id = features.patient_id
 
 				UNION ALL

				[4] AS resulted_on
			FROM
			(
				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 dbo.result_entities features
				INNER JOIN dbo.result_entities gvf ON gvf.id = features.parent_id
					AND gvf.attribute_id = 74  -- GVF result
				INNER JOIN dbo.result_entities res_dt ON res_dt.parent_id = gvf.id 
					AND res_dt.attribute_id = 72 -- Reference bases
				INNER JOIN dbo.result_entities snps ON snps.parent_id = features.id
				INNER JOIN dbo.attribute_relationships ar ON snps.attribute_id = ar.attribute1_id AND ar.relationship_id = 5
					AND ar.attribute2_id IN (34, 35)      -- F2, F5
				INNER JOIN dbo.patients p ON p.id = features.patient_id

				UNION ALL

				SELECT features.patient_id, features.id, snps.attribute_id AS [snp_id], refs.value_short_text,
					3 AS RowNum
				FROM dbo.result_entities features
				INNER JOIN dbo.result_entities refs ON refs.parent_id = features.id 
					AND refs.attribute_id = 100 -- Reference bases
				INNER JOIN dbo.result_entities snps ON snps.parent_id = features.id
				INNER JOIN dbo.attribute_relationships ar ON snps.attribute_id = ar.attribute1_id
					AND ar.relationship_id = 5     -- Variant of gene
					AND ar.attribute2_id IN (34, 35)      -- F2, F5
				WHERE features.attribute_id = 96   -- GVF Feature

				UNION ALL

				-- Grab GVF features, features have children specific SNPs, which have children SNP allele attributes
				-- Limit this to just SNPs that are under CYP2C19
				SELECT features.patient_id, features.id, snps.attribute_id AS [snp_id], alleles.value_short_text,
					ROW_NUMBER() OVER (PARTITION BY snps.id, snps.attribute_id ORDER BY features.patient_id, snps.attribute_id) AS RowNum
				FROM dbo.result_entities features
				INNER JOIN dbo.result_entities snps ON snps.parent_id = features.id 
				INNER JOIN dbo.attribute_relationships ar ON ar.attribute1_id = snps.attribute_id
					AND ar.relationship_id = 5     -- Variant of gene
					AND ar.attribute2_id IN (34, 35)      -- F2, F5
				INNER JOIN dbo.result_entities alleles ON alleles.parent_id = snps.id
					AND alleles.attribute_id = 128 -- SNP allele
				WHERE features.attribute_id = 96   -- GVF Feature
			) a
			PIVOT ( MAX(value_short_text) FOR RowNum IN ([1], [2], [3], [4]) ) AS pvt
		) v

					3 AS RowNum
				FROM dbo.result_entities features
				INNER JOIN dbo.result_entities refs ON refs.parent_id = features.id 
					AND refs.attribute_id = 100 -- Reference bases
				INNER JOIN dbo.result_entities snps ON snps.parent_id = features.id
				INNER JOIN dbo.attribute_relationships ar ON snps.attribute_id = ar.attribute1_id
					AND ar.relationship_id = 5     -- Variant of gene
					AND ar.attribute2_id = 32      -- CYP2C9
				WHERE features.attribute_id = 96   -- GVF Feature

				UNION ALL

				-- Grab GVF features, features have children specific SNPs, which have children SNP allele attributes
				-- Limit this to just SNPs that are under CYP2C19
				SELECT features.patient_id, features.id, snps.attribute_id AS [snp_id], alleles.value_short_text,
					ROW_NUMBER() OVER (PARTITION BY snps.id, snps.attribute_id ORDER BY features.patient_id, snps.attribute_id) AS RowNum
