Forum Discussion

tuanvinh1008's avatar
4 years ago

Can we edit SQL query on DBTables in running time

Hi all,

In the DBTables, we can customize the SQL query at the Design but how about if I want to modify the query in running time? because my scenario there are some field will be generated after do some steps.




4 Replies

  • mcbane's avatar
    Occasional Contributor

    If you're wanting the same thing I needed--YES!


    In JavaScript, I have variables setup as generic SQL queries. For example, to run a query against a specific account, I use a text variable with a value like:


    select *

    from table

    where account = 12345670


    Before I execute the query, I run a replace command to set it to the actual account I need for that particular run:


    Query = ProjectSuite.Variables.SQLQueryVariable.replace(new RegExp("12345670","g"),"8675309");
    RecSet = AConnection.Execute_(Query);


    TestComplete replaces 12345670 with the account number I need, and then executes the query.


    I hope this helps!


    • sonya_m's avatar
      SmartBear Alumni (Retired)

      Thanks everyone for trying to help!


      tuanvinh1008 did you manage to solve this? Looks like mcbane has an idea of what could work.

  • Hi tuanvinh1008 


    In TestComplete, I dont think you can modify the query at run time. 


    Happy to get another members response on that as I am not 100% certain.


    If needed, you could perhaps import dB libraries and maybe import a script to do this.  


    However, the query should still work no? 


    I mean your not creating new tables or columns every time you run a test or are you?