How to remove quotes from/use sortedColumn and sortedDesc in MSSQL statement

I have a SQL statement ending with the following:

…
ORDER BY dbo.AspNetUsers.{{ !!table1.sortedColumn ? table1.sortedColumn : 'AddedWhen' }} {{ table1.sortedDesc ? 'DESC' : 'ASC' }}
OFFSET {{ table1.paginationOffset }} ROWS
FETCH NEXT {{ table1.pageSize }} ROWS ONLY

The issue I have is both the results for sortedColumn and sortedDesc are wrapped in quotes, which MSSQL doesn't like.

Does anyone know how I can utilise these values in a way that is compatible?

Hey @chrisonretool!

It looks like you're trying to write your SQL in a way that won't work unless you disable prepared statements which can expose your resource to SQL injection attacks.

If you want to avoid that you might try using a case statement as described here. In this case, you would pass transformers where the parameters would be, something like:

Can you let us know if either of those options works?