Wednesday, November 6, 2013

The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified

CASE 1: if you are used order by clause in the following view
SELECT  
  C.customer_id
, C.customer_code
, C.customer_type_id
A.mobile ,A.email , A.phone
FROM clinic_customers C INNER JOIN address_details A ON A.address_id=C.address_id
order by C.last_update_on desc

You got following error message

The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified

do small change above code as follows it is working fine
CASE 2: if you can use order by clause in the following view
SELECT   TOP 100 PERCENT 
  C.customer_id
, C.customer_code
, C.customer_type_id
A.mobile ,A.email , A.phone
FROM clinic_customers C INNER JOIN address_details A ON A.address_id=C.address_id
order by C.last_update_on desc

No comments:

Post a Comment