在快速报告变量中分配值

时间:2014-10-02 07:14:18

标签: delphi delphi-xe2 fastreport

您好,我是德尔福的新人,而且我正在为新雇员创建报告。我使用的是Fast Report,Delphi XE2和Firebird数据库。

我在编写变量值的条件时遇到了问题。 如果EDU_COLL_REMARK字段值为空,我希望将变量的值作为处理值,例如' HIGH SCHOOL GRADUATE。和COLLEGE GRADUATE如果它有一个值..就像我一样。

if dmapp.sqtrans.parambyname('EDU_COLL_REMARK').IsNull then
        dmapp.frxReport1.Variables['edu'] := QuotedStr('HIGH SCHOOL GRADUATE');
else
   dmapp.frxReport1.Variables['edu'] := QuotedStr('COLLEGE GRADUATE');

但它不起作用。它返回一个

  

错误SQTrans:找不到参数EDU_COLL_REMARK。

什么错了?请帮帮我。

这是我的全部代码:

dmApp.sqTRANS.SQL.Clear;
   dmApp.sqtrans.SQL.Add('Select s.SKILLS_NAME, c.CUST_NAME, e.FULL_NAME, e.REFER_1NAME, e.HIRE_DATE, e.AGE, e.HEIGHT_FEET, e.HEIGHT_INCH, e.EDU_COLL_REMARK, e.TEST_1TITLE, e.SEC_EXPERIENCE_YEARS, e.CELL_NO, e.ADDRESS_LINE FROM EMPLOYEE e INNER JOIN CUSTOMER c ' +
                        'on e.CUST_NO=c.CUST_NO ' +
                        'FULL JOIN SKILLSTABLE s on e.SKILLS_NO=s.SKILLS_NO ' +
                        'WHERE EXTRACT(MONTH FROM HIRE_DATE) = :M_HIRE_DATE ' +
                        'AND EXTRACT(YEAR FROM HIRE_DATE) = :Y_HIRE_DATE ' +
                        'order by HIRE_DATE DESC');
    dmApp.sqTRANS.ParamByName('M_HIRE_DATE').AsString := FormatDateTime('MM', dpdate.Date);
    dmApp.sqTRANS.ParamByName('Y_HIRE_DATE').AsString := FormatDateTime('yyyy', dpdate.Date);
     if dmapp.sqtrans.parambyname('EDU_COLL_REMARK').IsNull then
        dmapp.frxReport1.Variables['edu'] := QuotedStr('HIGH SCHOOL GRADUATE');
else
dmapp.frxReport1.Variables['edu'] := QuotedStr('COLLEGE GRADUATE');
    dmApp.sqTRANS.ExecSQL();

    dmApp.frxDBDataset1.DataSet := dmApp.sqTRANS;
    dmApp.frxReport1.LoadFromFile('c:\vitech3\NewlyHired.fr3');
    dmapp.frxReport1.variables['COMPANYNAME'] := QuotedStr(Globals.GetCompanyName);
    dmapp.frxReport1.variables['COMPANYADD'] := QuotedStr(Globals.GetCompanyAddr + ' Cubao, Quezon City');
    dmapp.frxReport1.variables['CAPTION'] := QuotedStr('Newly Hired Report for ' + FormatDateTime('MMMM', dpdate.date) + ' ' + FormatDateTime('yyyy', dpdate.date));

    dmApp.frxReport1.ShowReport();

1 个答案:

答案 0 :(得分:1)

EDU_COLL_MARK不是'参数'你的查询;参数是带有'前缀的项目:'。

但是,从查询中返回所需的值。在Firebird文档中查看case .. when。这将向您展示如何从查询中返回条件值。

SELECT
 CASE EDU_COLL_MARK
   WHEN NULL THEN 'HIGH SCHOOL GRADUATE'
   ELSE 'COLLEGE GRADUATE'
 END AS EDU
FROM ...

--------------或者

SELECT
 CASE COALESCE(EDU_COLL_MARK, '')
   WHEN '' THEN 'HIGH SCHOOL GRADUATE'
   ELSE 'COLLEGE GRADUATE'
 END AS EDU
FROM ...