-- **********************************************************************************
-- get_taxonomy_ref_cwr_trait
-- **********************************************************************************
SELECT
	ct.taxonomy_ref_cwr_trait_id,
	ct.trait_code,
	ct.title,
	ct.description,
	ct.created_date,
	ct.created_by,
	ct.modified_date,
	ct.modified_by,
	ct.owned_date,
	ct.owned_by 
FROM
	taxonomy_ref_cwr_trait ct
INNER JOIN (
	SELECT 
		taxonomy_ref_cwr_trait_id 
	FROM 
		taxonomy_ref_cwr_trait
	WHERE 
		taxonomy_ref_cwr_trait_id  IN (:taxonomyrefcwrtraitid)) list 
	ON 
		list.taxonomy_ref_cwr_trait_id = ct.taxonomy_ref_cwr_trait_id

-- **********************************************************************************
-- get_taxonomy_ref_cwr_breeding_type
-- **********************************************************************************
SELECT  
	bt.taxonomy_ref_cwr_breeding_type_id,
	bt.breeding_type_code,
	bt.title,
	bt.description,
	bt.created_date,
	bt.created_by,
	bt.modified_date,
	bt.modified_by,
	bt.owned_date,
	bt.owned_by
FROM
	taxonomy_ref_cwr_breeding_type bt
INNER JOIN (
	SELECT 
		taxonomy_ref_cwr_breeding_type_id 
	FROM 
		taxonomy_ref_cwr_breeding_type
	WHERE 
		taxonomy_ref_cwr_breeding_type_id  IN (:taxonomyrefcwrbreedingtypeid)) list 
	ON 
		list.taxonomy_ref_cwr_breeding_type_id = bt.taxonomy_ref_cwr_breeding_type_id
	

-- **********************************************************************************
-- get_taxonomy_cwr_trait_map 
-- **********************************************************************************
SELECT
	tc.crop_name,
	ts.name,
	bt.title,
	t.title,
	t.trait_code,
	tm.taxonomy_cwr_trait_map_id,
	tm.taxonomy_crop_id,
	tm.taxonomy_species_id,
	tm.taxonomy_ref_cwr_breeding_type_id,
	tm.taxonomy_ref_cwr_trait_id,
	tm.breeding_usage_note,
	tm.ontology_trait_identifier,
	tm.citation_id,
	tm.note,
	tm.created_date,
	tm.created_by,
	tm.modified_date,
	tm.modified_by,
	tm.owned_date,
	tm.owned_by
FROM
	taxonomy_cwr_trait_map tm
JOIN
	taxonomy_crop tc
ON
	tm.taxonomy_crop_id = tc.taxonomy_crop_id
JOIN
	taxonomy_species ts
ON
	tm.taxonomy_species_id = ts.taxonomy_species_id
JOIN
	taxonomy_ref_cwr_breeding_type bt
ON
	tm.taxonomy_ref_cwr_breeding_type_id = bt.taxonomy_ref_cwr_breeding_type_id
JOIN
	taxonomy_ref_cwr_trait t
ON
	tm.taxonomy_ref_cwr_trait_id = t.taxonomy_ref_cwr_trait_id
INNER JOIN (
	SELECT 
		taxonomy_cwr_trait_map_id 
	FROM 
		taxonomy_cwr_trait_map 
	WHERE 
		taxonomy_cwr_trait_map_id IN (5,6,7,8,9)) list 
	ON 
		list.taxonomy_cwr_trait_map_id = tm.taxonomy_cwr_trait_map_id

-- **********************************************************************************
-- cwr_breeding_type_lookup
-- **********************************************************************************
SELECT
  b.taxonomy_ref_cwr_breeding_type_id AS value_member,
  b.title AS display_member
FROM
 taxonomy_ref_cwr_breeding_type b
WHERE
  ((b.created_date > COALESCE(:createddate, '1753-01-01'))
   OR (b.modified_date > COALESCE(:modifieddate, '1753-01-01'))
   OR (b.method_id IN (:valuemember))
   OR (b.method_id BETWEEN :startpkey AND :stoppkey)
 )

 -- **********************************************************************************
-- cwr_trait_lookup
-- **********************************************************************************
SELECT
	t.taxonomy_ref_cwr_trait_id AS value_member,
	t.title AS display_member
FROM
	taxonomy_ref_cwr_trait t
WHERE
  ((t.created_date > COALESCE(:createddate, '1753-01-01'))
   OR (t.modified_date > COALESCE(:modifieddate, '1753-01-01'))
   OR (t.method_id IN (:valuemember))
   OR (t.method_id BETWEEN :startpkey AND :stoppkey)
 )