How can I order by a variable in a raw query? ```c...
# orm-help
y
How can I order by a variable in a raw query?
Copy code
const order = 'last_name ASC, first_name ASC';

await prisma.$queryRaw`SELECT *
                       FROM users
                       ORDER BY ${order}`;
I'm getting this error `Raw query failed. Code:
1008
. Message: `The SELECT item identified by the ORDER BY number 1 contains a variable as part of the expression identifying a column position. Variables are only allowed when ordering by an expression referencing a column name.`` Using SQL Server
a
Hey Yaakov šŸ‘‹ , This looks like a SQL Server-specific error that I’m unsure how to resolve. You could look through this page to see if any of those solutions work for you, otherwise you could use plain string concatenation instead of template literals. Just be sure to sanitize the inputs before sending them to the DB šŸ˜„.
y
Thank you!