Skip to content
Advertisement

A constant expression was encountered in the ORDER BY list

Below is my dynamic query and it’s not working.

It threw:

A constant expression was encountered in the ORDER BY list, position 2.

Original dynamic query:

Extracted Query:

If I remove second order by line, CASE WHEN 'ItemDescription'='ItemDescription' AND '0'= '1' THEN cteForPriceVen.ItemDescription END DESC the query seems working.

Advertisement

Answer

The second line:

Is equivalent to NULL. You can’t order something by NULL.

edit

If this statement is being generated by a dynamic query, what you need to do is fix the way you build the dynamic query:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement