Shaan

Shaan

  • NA
  • 110
  • 13.7k

"Ambiguous column name 'Id'"

Aug 28 2022 3:41 AM

Hi everyone.
Doesn't it work with order by alias bound to the parameter?

My order by:

ORDER BY CASE
             WHEN @ordercolumn = 'Id' THEN Id
             WHEN @ordercolumn = 'Username' THEN Username
             END

I get error "Ambiguous column name 'Id'"

My select:

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


Answers (3)