Gen EDGE

  • 1.  How to write a dynamic SQL?

    Posted Jun 25, 2017 05:47 AM

    Hi,

    I need to create a dynamic SQL with a fields/parameters entered by the users. 

     

    Example:

    I know user will whant to query file1, but they may want to query (field1 > xx and field1 <yyy) but they can also whant to query (field1 = ZZZ and field2 like 'sss%')
    Any ideas how do this on the toolset? it is possible?

    Thanks a lot,
    Cristina



  • 2.  Re: How to write a dynamic SQL?
    Best Answer

    Posted Jun 26, 2017 11:44 AM

    The solution depends on how much flexibility you want to provide the user. If you want to allow the user to enter all of the SQL after the WHERE clause then you could use dynamic SQL in an EAB or inline code. The SELECT columns can be bound to entity action views so that you can place the returned data into your export view and you could create the SQL text from a combination of a hardcoded SELECT (columns) and FROM (tables) with a user entered WHERE clause. The EAB/inline code would then run the dynamic SQL and trap any incorrect syntax entered by the user. This option would require the user to have a good knowledge of SQL and the table structure. 

     

    An alternative would be where you provide a form that allows them to select columns, operators (=, <, >, etc) and values and then you build the sql in your logic from the choices made by the user. This would be less flexible and more effort to develop but would allow you to constrain the user to sensible choices and not require them to have the detailed knowledge of the first option.



  • 3.  Re: How to write a dynamic SQL?

    Posted Aug 17, 2017 01:13 PM

    Tks Darius :-)