The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries

前端 未结 2 1085
情歌与酒
情歌与酒 2021-01-29 11:33

my stored procedeur like this:

alter PROCEDURE [dbo].[ParkingDeatailsReportnewstack] 
      @startdate NVARCHAR(100),
      @enddate NVARCHAR(100)AS
BEGIN
    DE         


        
相关标签:
2条回答
  • 2021-01-29 12:00

    Try migrating your order by clause into the outermost select statement — the only place where order by makes any sense.

    Something like

    select LocName ,
           ...
    from ...
    order by LocName
    

    Or, even simpler, wrap the original, complex select in an outer select whose sole purpose is ordering, along these lines:

    select *
    from ( select
           ...   
         ) t
    order by t.x, t.y , ... 
    
    0 讨论(0)
  • 2021-01-29 12:14

    We can fix the problem very easily by adding a TOP 100 PERCENT clause into the view definition. Try using this way - http://www.sqlpassion.at/archive/2015/05/25/the-ambiguity-of-the-order-by-in-sql-server/

    0 讨论(0)
提交回复
热议问题