Customer Portal

Dynamic SQL execution based on column value

Comments 7

  • Avatar
    imriskal
    0
    Comment actions Permalink
    Hello,

    This should be quite straghtforward, see the example graph. The bottom line is that SQL does not have to be defined in CTL as a local variable, it should be a metadata field.

    I hope this helps.
    dynamic_sql.grf
  • Avatar
    cwe6279
    0
    Comment actions Permalink
    thanks, I got the result(sort of). However, one small issue which I'm sure is a noob issue, but I don't understand why it's happening. The file written back out looks like this:

    1||
    1||
    1||
    10||


    So, it wrote the value retieved in SQL, but I lost my other two columns and values, any idea why that would be? Do you have to explicitly write out columns from a previous step? I thought the auto propogation would do that.

    thanks!
  • Avatar
    cwe6279
    0
    Comment actions Permalink
    adding the .grf for reference re: previous reply

    thanks
  • Avatar
    cwe6279
    0
    Comment actions Permalink
    I did figure out one small fix according to the docs...didn't realize I needed to explicitly assign the result back to the "SQL" metadata column which I did by changing my string to (it seemed to work):

    $out.0.SQL = concat("SELECT ","$SQL:=","COUNT(DISTINCT ", $in.0.Column,") FROM ", $in.0.Table);



    However, I'm not sure still how to avoid losing the original Table and Column name values from the input port data?

    thanks!
  • Avatar
    imriskal
    0
    Comment actions Permalink
    Even though some components allow mapping input values to output, DBInputTable is unfortunately not one of them.

    In this case, where DB query returns only one result, it is possible to use SimpleCopy before the DBInputTable and Combine after it.
  • Avatar
    cwe6279
    0
    Comment actions Permalink
    Thanks Lubos,

    OK, I managed with your suggestion to copy port 0 Table and column and Port 1 SQL but this is concerning to me as there is no key matching happening between data sets is there? How certain can I be that the original table and column name will be matched correctly to the SQL value returned? Like if one entry fails then I assume it's working only off an internal row sequence number- how reliable is this in terms of retaining the proper order and row counts?

    thanks again!

    Charles
  • Avatar
    slechtaj
    0
    Comment actions Permalink
    Hi Charles,

    Combine component should be used in cases where you are hundred percent sure that data comes in tuples. However, without any further check data are not checked to be in required order etc. Therefore, if you need to introduce joining based on a key you might simply use a key in the query and then use ExtMergeJoin instead of Combine. This is very simple to use and prevent any "incorrect" data joining. See the example for more information.

    DBQueryWithKey.grf
    Hope this helps.

Please sign in to leave a comment.