#Parameterising Order Column name and sort order for MySQL quries

1 messages · Page 1 of 1 (latest)

lost pollen
#

Hi team,

I need to parameterise the ordering column name and sort order (ASC/DESC) in a sql:ParameterizedQuery

i.e: SELECT * FROM <TABLE_NAME> ORDER BY ${<COLUMN_NAME>} ${<SORT_ORDER>}

Here is the code I tried to use, but this doesn't seems to be working.

sqlQuery = sql:queryConcat( sqlQuery, ` ORDER BY ${'order.columnName} ${'order.sortOrder}`)

I guess only the values are supported as params in sql:ParameterizedQuery.

Can you look into this and help me out to fix this issue?

Thanks.

vapid wigeon
#

@brittle grail

brittle grail
#

Hi @lost pollen ,

Yes you are correct. Only values are supported as params. For this use case, you have to have multiple sql:ParameterizedQuery defined.

The specific query can be selected using a match case.

lost pollen
#

Hi @brittle grail , Thanks for the clarification.