sql server - SQL: Use a predefined list in the where clause -
here example of trying do:
def famlist = selection.getunique('family_code') ... “””... , testedwaferpass.family_code in $famlist “””...
famlist list of objects
‘selection’ change every run, list changing.
i want return columns sql search row found in list have created.
i realize supposed like: in ('foo','bar')
but no matter do, list not that. have turn list string?
('\${famlist.join("', '")}')
ive tried above, idk. wasn’t working me. thought throw in there. love suggestions. thanks.
i willing bet there groovier way implement shown below - works. here's important part of sample script. namelist original contains string names. need quote each entry in list, string [ , ] tostring result. tried passing prepared statement need dynamically create string ? each element in list. quick-hack doesn't use prepared statement.
def namelist = ['reports', 'customer', 'associates'] def nameliststring = namelist.collect{"'${it}'"}.tostring().substring(1) nameliststring = nameliststring.substring(0, nameliststring.length()-1) string stmt = "select * action_group_i18n name in ( $nameliststring)" db.eachrow( stmt ) { row -> println "$row.action_group_id, $row.language, $row.name" }
hope helps!
Comments
Post a Comment