From: esquel@sommarskog.se   
      
   Anton Shepelev (anton.txt@g{oogle}mail.com) writes:   
   > Surprising indeed, nor do I think this unexpected difference   
   > is documented, seeming like a bug.   
      
   The Docs are smart enough to be sufficiently vague:   
      
    Depending on the ranking, aggregate, or analytic function used with the   
    OVER clause, and/or the may not   
    be supported.   
      
   So it certainly permits for this exception.   
      
   But I could certainly argue that it is a bug in that the error   
   message should be semantic, and not a parsing error.   
      
   But now for some interesting news. In SQL 2022, they introduced the   
   WINDOW clause:   
      
   SELECT object_id, column_id, SUM(column_id) OVER MyWindow   
   FROM sys.columns   
   WINDOW MyWindow AS (PARTITION BY object_id   
    ORDER BY column_id ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)   
   ORDER BY object_id, column_id   
      
   This is useful when you want to use the same Windows clause for multiple   
   columns in the same query, as you only have to define it in one place.   
      
   So what about this?   
      
   SELECT object_id, column_id, dbo.integerlist(column_id) OVER MyWindow   
   FROM sys.columns   
   WINDOW MyWindow AS (PARTITION BY object_id   
    ORDER BY column_id ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)   
   ORDER BY object_id, column_id   
      
   Yes, it runs and returns the correct result.   
      
   However, I need to add a caveat here: The fact that this runs might   
   be a bug. I seem to recall that there is something about CLR   
   aggregates and ordering. That is, if this runs but produces an   
   incorrect result, this is not good. Then again, my aggregate is   
   supposed to return an ordered result, and it seems to do with my   
   test query. But that may be due to chance.   
      
   I will need to bring this up with some people at Microsoft.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|