Solved
Forum Discussion
Prabaharan
7 years agoContributor
Thanks for your quick reply.
I have implemented this project as a data driven for which few the values are fetched from an external file.
Few records for the same column will hold a valid value and rest other will hold null for the same column itself, so which i will not be able to remove the column from the sql query itself.
Hope this gives you better clarification
JHunt
7 years agoCommunity Hero
Here's a solution you could try, but it's pretty ugly.
Change your SQL to like this:
INSERT INTO db2admin1.cdaddrusagetp (${=
def aliases = [
"LangType": "LANG_TP_CD",
"AddUsageTp": "ADDR_USAGE_TP_CD",
// TODO
]
def columns = []
for (def prop: context.testStep.propertyList)
columns += prop.name != "ResponseAsXml" && prop.value != "NULL"
? aliases[prop.name]
: []
columns.join(', ')
}) VALUES (${=
def values = []
for (def prop: context.testStep.propertyList)
values += prop.name != "ResponseAsXml" && prop.value != "NULL"
? ":" + prop.name
: []
values.join(', ')
})
Here's the thing. We can write Groovy in the SQL request by using the ${= } syntax, but the syntax breaks down if we use brackets { } in the Groovy script. So above is not exactly how I'd prefer to write the script, but it doesn't have any brackets in it.