Skip to content

Instantly share code, notes, and snippets.

@tomgullo
Created August 28, 2009 03:26
Show Gist options
  • Save tomgullo/176760 to your computer and use it in GitHub Desktop.
Save tomgullo/176760 to your computer and use it in GitHub Desktop.
groovy sql with like clause
def query_params = []
def and_where_string = ''
if (params.name) {
and_where_string = " and where upper(name) like ? "
query_params << "%" + params.name.toUpperCase() + "%"
}
def query = """
select * from table
where table.id is not null
$and_where_string
"""
def rows
if (and_where_string) {
rows = sql.rows(query, query_params)
} else {
rows = sql.rows(query)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment