IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.



#Automation


#Applicationintegration
#webMethods
#Integration
 View Only
  • 1.  Interesting question on dynamic query

    Posted 06/16/15 07:56 AM

    Dear All,
    Hope all are doing good.
    Lets say I have select query but where condition should be added if any of the option parameters( 5 parameters ) are having value in the flow service.I mean,
    Let’s say there are 5 optional parameters ( a,b,c,d,e) as part of my flow service.If a,b,c,d &e are having values then my query should be
    select * from <table_Name> where a=? and b=? and c=? and d=? and e=?
    If I am getting only b and e then my query should be
    select * from <table_Name> where b=? and e=?
    If I am not getting any values as part of 5 option parameters then my query should be
    select * from <table_Name>

    Can someone has idea how to build query for this requirement

    Thanks,
    Anil.


    #Integration-Server-and-ESB
    #Adapters-and-E-Standards
    #webMethods


  • 2.  RE: Interesting question on dynamic query

    Posted 06/16/15 03:45 PM

    Hi Anil,

    can you try the following Pseudo-Code?

    
    selectQuery = "select * from <table name>"
    whereClause = "" (means empty string)
    
    branch on a not empty
    true: whereClause = whereClause + "a = <value for a>"
    
    branch on b not empty
    true: branch on whereClause.length > 0
    true: whereClause = whereClause + " and "
    whereClause = whereClause + "b = <value for b>"
    
    branch on c not empty
    true: branch on whereClause.length > 0
    true: whereClause = whereClause + " and "
    whereClause = whereClause + "c = <value for c>"
    
    branch on d not empty
    true: branch on whereClause.length > 0
    true: whereClause = whereClause + " and "
    whereClause = whereClause + "d = <value for d>"
    
    branch on e not empty
    true: branch on whereClause.length > 0
    true: whereClause = whereClause + " and "
    whereClause = whereClause + "e = <value for e>"
    
    branch on whereClause.length > 0
    true: selectQuery = selectQuery + " where " + whereClause
    
    execute selectQuery

    Missing false-branches mean “Do nothing here”.

    We have used similar implementations in our project successfully.

    See also the following thread (Custom SQL vs. Dynamic SQL):

    Regards,
    Holger


    #Adapters-and-E-Standards
    #Integration-Server-and-ESB
    #webMethods


  • 3.  RE: Interesting question on dynamic query

    Posted 06/16/15 05:21 PM

    Thanks Holger, it meets my requirement.

    Thanks,
    Anil


    #Adapters-and-E-Standards
    #webMethods
    #Integration-Server-and-ESB


  • 4.  RE: Interesting question on dynamic query

    Posted 06/17/15 12:05 PM


  • 5.  RE: Interesting question on dynamic query

    Posted 06/17/15 05:01 PM

    Percio, can you please give more details, if possible give some pseudo code.

    Thanks,
    Anil.


    #webMethods
    #Integration-Server-and-ESB
    #Adapters-and-E-Standards


  • 6.  RE: Interesting question on dynamic query

    Posted 06/17/15 05:47 PM

    The logic is basically the same. I’m just suggesting that you should perhaps host it on the database, which would make more sense to me. In that case, from the Integration Server, you would always call the stored procedure in exactly the same way every time, by mapping your variables to the procedure’s input, regardless of whether the variables were null or not. The stored procedure would be the one responsible for analyzing each variable to determine whether it should be included in the where clause or not.

    Percio


    #Adapters-and-E-Standards
    #Integration-Server-and-ESB
    #webMethods