|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Dynamic query for DB2 in ESQL |
« View previous topic :: View next topic » |
Author |
Message
|
AnshumanMishra861 |
Posted: Tue Apr 19, 2022 6:09 am Post subject: Dynamic query for DB2 in ESQL |
|
|
Newbie
Joined: 19 Apr 2022 Posts: 2
|
I am connecting ACE with DB2. I am getting a JSON request with FieldNames and Values and I need to fetch data from DB based on those values.
While fetching data in DB2, it's working in below format if the field in NULL
'SELECT * FROM table WHERE column1 IS NULL'
but if the field has some values the query should be
'SELECT * FROM table WHERE column1 = "value" '
I have multiple columns that can be either NULL or may have some values.
I am creating the SQL query in esql as below
SET env.var[] = PASSTHRU('SELECT * FROM table WHERE column1 = ? AND column2 = ?' VALUES(env.Column1_value,env.Column2_value) );
But this works only if the fields have some values.
Is there any way I can change the query dynamically to below, depending on the field values?
SET env.var[] = PASSTHRU('SELECT * FROM table WHERE column1 IS NULL AND column2 = ?' VALUES(env.Column2_value) );
I am getting 10 columns in input. Below is a sample input format that I might receive
{
"searchKeys": {
"column1": "value",
"column2": "value",
"column3": "",
"column4": "",
"column5": "value",
"column6": "",
"column7": "value",
"column8": "",
"column9": "",
"column10": ""
}
} |
|
Back to top |
|
 |
timber |
Posted: Tue Apr 19, 2022 6:42 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
You can do it, but you cannot use ? parameters in your SELECT statement. You will need to build the entire SELECT statement using ESQL.
Make sure you validate your JSON input to avoid SQL injection attacks. |
|
Back to top |
|
 |
AnshumanMishra861 |
Posted: Tue Apr 19, 2022 7:14 am Post subject: |
|
|
Newbie
Joined: 19 Apr 2022 Posts: 2
|
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|