Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

TdaSQLBuilder and Expression

edited December 2005 in General
Hi All,

How to use TdaSQLBuilder to create a expression calcfield with field
alias in the statement result?

i.e.:
SELECT tab.cod, 2 ide FROM tab

When I tried to use calcfield, the Sql statement generated by
TdaSQLBuilder was:
SELECT tab.cod, 2 2 FROM tab

TIA,
Laercio

Comments

  • edited December 2005
    Hi Laercio,

    Please post the TdaSQLBuilder code you are using and I will test it on my
    machine.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited December 2005
    Nico Cizik (Digital Metaphors) escreveu:


    aSql := TdaSQLBuilder.Create( ppReport1 );
    aSql.Clear;
    aSql.SelectFields.Add( 'TAB', 'COD' );
    aSql.CalcFields.AddExpression( '2 AS IDE' );


    // Result: SELECT TAB.COD, 2 2 FROM TAB
    //
    // I expected: SELECT TAB.COD, 2 IDE FROM TAB


    By the way: I'm using D7, RB 9.02, Oracle 9i


    TIA,
    Laércio
  • edited December 2005
    Hi Laercio,

    The expression cannot contain a field alias. The best way to determine what
    is allowed in the TdaSQLBuilder is to try it first in the Query Designer.

    It is possible to change the SQL Field alias of a calcuated field using the
    code below, however ReportBuilder does not use this value at any time during
    design or generation. You may want to change the Field Alias instead.

    aSql := TdaSQLBuilder.Create( ppReport1 );
    aSql.Clear;
    aSql.SelectFields.Add( 'TAB', 'COD' );
    lCalcField := aSql.CalcFields.AddExpression( '2' );

    //Change SQL Field Alias (not needed)
    lCalcField.SQLFieldName := 'IDE';

    //Change Field Alias (used by RB)
    lCalcField.FieldAlias := 'IDE';

    aSQL.ApplyUpdates;


    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.