# How to add variable in SQL query while fetching data so Based on variable in Data source as Database in kaalon

**URL:** <https://forum.katalon.com/t/how-to-add-variable-in-sql-query-while-fetching-data-so-based-on-variable-in-data-source-as-database-in-kaalon/138864>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [July 28, 2024, 9:36am UTC](https://forum.katalon.com/t/how-to-add-variable-in-sql-query-while-fetching-data-so-based-on-variable-in-data-source-as-database-in-kaalon/138864 "2024-07-28T09:36:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![siddarth.punamiya](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/siddarth.punamiya/32/16104_2.png) [@siddarth.punamiya](https://forum.katalon.com/u/siddarth.punamiya)\
**Post date:** [July 28, 2024, 9:36am UTC](https://forum.katalon.com/t/how-to-add-variable-in-sql-query-while-fetching-data-so-based-on-variable-in-data-source-as-database-in-kaalon/138864/1 "2024-07-28T09:36:32Z")

</div>

Hi Team,  
Need some help  
I have selected datasourse as database in datafiles  
And wrote SQL query to fetch data and added same data file in test suite as data source

Now I want that the SQL query which I used as Where condition in which I am passing one number

But now I want to pass Variable against it so

When I run test suite then based on that number Data should be fetched in test suite and then test suite should get executed as per the records in it

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/katalon/original/3X/d/5/d55596ab02785a255798e87ede769734747b30c4.svg) [@system](https://forum.katalon.com/u/system)\
**Post date:** [July 28, 2024, 9:36am UTC](https://forum.katalon.com/t/how-to-add-variable-in-sql-query-while-fetching-data-so-based-on-variable-in-data-source-as-database-in-kaalon/138864/2 "2024-07-28T09:36:32Z")

</div>

Hi there,

Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.

Thanks!

---

<div class="post-metadata">

**Author:** ![Dave\_Evers](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/dave_evers/32/435_2.png) [@Dave\_Evers](https://forum.katalon.com/u/Dave_Evers)\
**Post date:** [July 28, 2024, 4:03pm UTC](https://forum.katalon.com/t/how-to-add-variable-in-sql-query-while-fetching-data-so-based-on-variable-in-data-source-as-database-in-kaalon/138864/3 "2024-07-28T16:03:17Z")

</div>

Hi @siddarth.punamiya, if you have access to Copilot or Chatgpt you could do a query like this: How to do data driven testing and pass variables using SQL in Katalon Studio.

---

<div class="post-metadata">

**Author:** ![Elly\_Tran](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/elly_tran/32/21874_2.png) [@Elly\_Tran](https://forum.katalon.com/u/Elly_Tran)\
**Post date:** [July 29, 2024, 9:14am UTC](https://forum.katalon.com/t/how-to-add-variable-in-sql-query-while-fetching-data-so-based-on-variable-in-data-source-as-database-in-kaalon/138864/4 "2024-07-29T09:14:59Z")

</div>

Hi @siddarth.punamiya,

Thank you for sharing your issue. I would like to suggest the following steps:

1. **Define a Test Suite Variable:**

2. **Modify the SQL Query:**

3. **Script to Set SQL Query Dynamically:**

4. **Run the Test Suite:**

Please try and let me know if it works

---

<div class="post-metadata">

**Author:** ![siddarth.punamiya](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/siddarth.punamiya/32/16104_2.png) [@siddarth.punamiya](https://forum.katalon.com/u/siddarth.punamiya)\
**Post date:** [August 17, 2024, 5:32am UTC](https://forum.katalon.com/t/how-to-add-variable-in-sql-query-while-fetching-data-so-based-on-variable-in-data-source-as-database-in-kaalon/138864/5 "2024-08-17T05:32:14Z")

</div>

Please upvote for my idea as Katalon is not supporting this feature and they have decided to take it up in there future releases  
But if it gets good votes then they can implement this ASAP

Below is the link for my Idea which I posted

[https://katalon-inc.my.site.com/katalonhelpcenter/s/kidea/a1vRA0000009yZdYAI/id00000113](https://katalon-inc.my.site.com/katalonhelpcenter/s/kidea/a1vRA0000009yZdYAI/id00000113)

---

<div class="post-metadata">

**Author:** ![Dan\_Bown](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/dan_bown/32/20464_2.png) [@Dan\_Bown](https://forum.katalon.com/u/Dan_Bown)\
**Post date:** [August 17, 2024, 9:00pm UTC](https://forum.katalon.com/t/how-to-add-variable-in-sql-query-while-fetching-data-so-based-on-variable-in-data-source-as-database-in-kaalon/138864/6 "2024-08-17T21:00:46Z")

</div>

Just some feedback. You have described how you think the solution should be implemented but not described clearly what the problem is. Is the solution from @Elly_Tran what is required? I mean it sounds like Data Driven Testing?

---

<div class="post-metadata">

**Author:** ![siddarth.punamiya](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/siddarth.punamiya/32/16104_2.png) [@siddarth.punamiya](https://forum.katalon.com/u/siddarth.punamiya)\
**Post date:** [August 29, 2024, 4:02pm UTC](https://forum.katalon.com/t/how-to-add-variable-in-sql-query-while-fetching-data-so-based-on-variable-in-data-source-as-database-in-kaalon/138864/7 "2024-08-29T16:02:08Z")

</div>

Hi I cannot see Set Variable option in Test Suite itself first and second thing i am directly fetching the data from Database by using Test Data as Database connection and query settings

I am also facing one more issue  
when running the same Test suite it fails because below error  
Data source is .dat file in which jdbc:oracle:thin:@DBname   
DBData  
  
false  
passwd  
  
  
readAsString  
true  
  
  
SELECT query

On Jenkins its failing do you know why

com.kms.katalon.execution.exception.ExecutionException: java.lang.IllegalArgumentException: Data source of test data: Data Files/ProductHub/ChangeControlData/CCUIBevDeleteUpdate is not available.  
at com.kms.katalon.execution.entity.TestCaseBindingExecutedEntity.prepareTestCase(TestCaseBindingExecutedEntity.java:65)
