Hi everyone.
Doesn't it work with order by alias bound to the parameter?
My order by:
SQL
ORDER BY CASE
WHEN @ordercolumn = 'Id' THEN Id
WHEN @ordercolumn = 'Username' THEN Username
ENDI get error "Ambiguous column name 'Id'"
My select:
SQL
SELECT DISTINCT P.Id,
P.Username Username,
………I can't post the whole code because it's 150 lines but there are no other Id columns in the selection

Uday DodiyaRank #239 · 10.3K reputationPosted Aug 28, 2022, 1:00 AM EDT
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Aug 28, 2022, 1:18 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Aug 29, 2022, 12:38 AM EDT