| 1 | select
|
|---|
| 2 | a.accession_id as 'Accession ID',
|
|---|
| 3 | '' + (coalesce(a.accession_number_part1,'') + ' ' + coalesce(convert(nvarchar, a.accession_number_part2), '') + ' ' + coalesce(a.accession_number_part3,'')) + '' as 'Plant ID',
|
|---|
| 4 | coalesce(ctl.title, ct.coded_name) as crop_trait_name,
|
|---|
| 5 | coalesce(coalesce(ctcl.title, ctc.code, convert(nvarchar, cto.crop_trait_code_id)), string_value, convert(nvarchar, cast(numeric_value as float))) as value
|
|---|
| 6 | from
|
|---|
| 7 | crop_trait_observation cto
|
|---|
| 8 | inner join crop_trait ct
|
|---|
| 9 | on cto.crop_trait_id = ct.crop_trait_id
|
|---|
| 10 | left join crop_trait_lang ctl
|
|---|
| 11 | on ct.crop_trait_id = ctl.crop_trait_id
|
|---|
| 12 | and ctl.sys_lang_id = 1
|
|---|
| 13 | left join crop_trait_code ctc
|
|---|
| 14 | on cto.crop_trait_code_id = ctc.crop_trait_code_id
|
|---|
| 15 | left join crop_trait_code_lang ctcl
|
|---|
| 16 | on ctc.crop_trait_code_id = ctcl.crop_trait_code_id
|
|---|
| 17 | and ctcl.sys_lang_id = 1
|
|---|
| 18 | left join inventory i
|
|---|
| 19 | on cto.inventory_id = i.inventory_id
|
|---|
| 20 | left join accession a
|
|---|
| 21 | on i.accession_id = a.accession_id
|
|---|
| 22 | where (cto.is_archived = 'N' and cto.crop_trait_id = 89027 and cto.crop_trait_code_id IN (3909) ) and ( a.accession_id in ( select accession_id from inventory where inventory_id in (
|
|---|
| 23 | select inventory_id
|
|---|
| 24 | from crop_trait_observation cto where (cto.is_archived = 'N' and cto.crop_trait_id = 89027 and cto.crop_trait_code_id IN (3909) ) )) and a.accession_id in ( select accession_id from inventory where inventory_id in (
|
|---|
| 25 | select inventory_id
|
|---|
| 26 | from crop_trait_observation cto where (cto.is_archived = 'N' and cto.crop_trait_id = 89026 and cto.crop_trait_code_id IN (3904) ) )) ) Union
|
|---|
| 27 | select
|
|---|
| 28 | a.accession_id as 'Accession ID',
|
|---|
| 29 | '' + (coalesce(a.accession_number_part1,'') + ' ' + coalesce(convert(nvarchar, a.accession_number_part2), '') + ' ' + coalesce(a.accession_number_part3,'')) + '' as 'Plant ID',
|
|---|
| 30 | coalesce(ctl.title, ct.coded_name) as crop_trait_name,
|
|---|
| 31 | coalesce(coalesce(ctcl.title, ctc.code, convert(nvarchar, cto.crop_trait_code_id)), string_value, convert(nvarchar, cast(numeric_value as float))) as value
|
|---|
| 32 | from
|
|---|
| 33 | crop_trait_observation cto
|
|---|
| 34 | inner join crop_trait ct
|
|---|
| 35 | on cto.crop_trait_id = ct.crop_trait_id
|
|---|
| 36 | left join crop_trait_lang ctl
|
|---|
| 37 | on ct.crop_trait_id = ctl.crop_trait_id
|
|---|
| 38 | and ctl.sys_lang_id = 1
|
|---|
| 39 | left join crop_trait_code ctc
|
|---|
| 40 | on cto.crop_trait_code_id = ctc.crop_trait_code_id
|
|---|
| 41 | left join crop_trait_code_lang ctcl
|
|---|
| 42 | on ctc.crop_trait_code_id = ctcl.crop_trait_code_id
|
|---|
| 43 | and ctcl.sys_lang_id = 1
|
|---|
| 44 | left join inventory i
|
|---|
| 45 | on cto.inventory_id = i.inventory_id
|
|---|
| 46 | left join accession a
|
|---|
| 47 | on i.accession_id = a.accession_id
|
|---|
| 48 | where (cto.is_archived = 'N' and cto.crop_trait_id = 89026 and cto.crop_trait_code_id IN (3904) ) and ( a.accession_id in ( select accession_id from inventory where inventory_id in (
|
|---|
| 49 | select inventory_id
|
|---|
| 50 | from crop_trait_observation cto where (cto.is_archived = 'N' and cto.crop_trait_id = 89027 and cto.crop_trait_code_id IN (3909) ) )) and a.accession_id in ( select accession_id from inventory where inventory_id in (
|
|---|
| 51 | select inventory_id
|
|---|
| 52 | from crop_trait_observation cto where (cto.is_archived = 'N' and cto.crop_trait_id = 89026 and cto.crop_trait_code_id IN (3904) ) )) ) order by 1, 2, 3 |
|---|