如何将主报表字段传递给子报表查询

时间:2015-09-08 05:25:49

标签: mysql join jasper-reports

如何将主报表字段传递给子报表查询。 主报告查询:

select pd.ID_DIMENSION as IDDIM,
    pd.NOMBRE as pdnombre,
    pdi.VALOR_PONDERACION_GOB as pdipond,
    pdi.VALOR_PONDERADO as pdiponderado 
from pgs_indice pi 
    join pgh_indice_vigencia piv on piv.ID_INDICE = pi.ID_INDICE 
    JOIN pgh_dimension_indice pdi ON piv.ID_INDICE_VIGENCIA = pdi.ID_INDICE_VIGENCIA 
    JOIN pgb_dimension pd ON pd.ID_DIMENSION = pdi.ID_DIMENSION 
where pi.ID_INDICE = $P{INDICE} AND piv.VIGENCIA = $P{VIGENCIA}

子报告查询:

SELECT DISTINCT pc.NOMBRE as pcnombre,
    pcd.VALOR_PONDERACION_GOB as pcdpond,
    pcd.VALOR_PONDERACION as pcdponderacion,
    FORMAT(((pcd.VALOR_PONDERACION_GOB * 100) / (pcd.VALOR_PONDERACION_GOB + pcd.VALOR_PONDERACION)),2) as pcdpondgobcal,
    FORMAT(((pcd.VALOR_PONDERACION * 100) / (pcd.VALOR_PONDERACION_GOB + pcd.VALOR_PONDERACION)),2) as pcdpondcal
FROM pgs_indice indi 
    JOIN pgh_indice_vigencia piv ON piv.ID_INDICE = indi.ID_INDICE 
    JOIN pgh_dimension_indice pdi ON piv.ID_INDICE_VIGENCIA = pdi.ID_INDICE_VIGENCIA 
    JOIN pgb_dimension pd ON pd.ID_DIMENSION =pdi.ID_DIMENSION 
    JOIN pgh_categoria_dimension pcd ON pcd.ID_DIMENSION_INDICE = pdi.ID_DIMENSION_INDICE 
    JOIN pgb_categoria pc ON pc.ID_CATEGORIA = pcd.ID_CATEGORIA 
    JOIN pgh_indicador_categoria pic ON pic.ID_CATEGORIA_DIMENSION = pcd.ID_CATEGORIA_DIMENSION 
    JOIN pgb_indicador pi ON pi.ID_INDICADOR = pic.ID_INDICADOR 
WHERE indi.ID_INDICE = $P{INDICE} 
    AND piv.VIGENCIA =  $P{VIGENCIA}  
    AND pd.ID_DIMENSION =1 Here 

我希望在子报表查询中使用主报表字段('pd.ID_DIMENSION as IDDIM,')where condition:

(WHERE indi.ID_INDICE = $P{INDICE} AND piv.VIGENCIA =  $P{VIGENCIA}  AND pd.ID_DIMENSION = Here I want use)

1 个答案:

答案 0 :(得分:0)

你需要将参数pd.ID_DIMENSION传递给子报告。

  1. 在主报表中,单击子报表,在属性中单击“参数”。
  2. 它会带参数框。单击“添加”,输入参数名称,例如:ID_DIMENSION
  3. 对于“值表达式”,选择要传递给子报表的字段,例如:$F{ID_DIMENSION}
  4. 在您的子报告中,添加新的参数,并将其命名为您从主报告传递的内容ID_DIMENSION
  5. 更改子报表查询以使用主报表中的参数。 ... AND pd.ID_DIMENSION = $P{ID_DIMENSION}
  6. 祝你好运。