home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 19,451 of 19,505   
   Erland Sommarskog to Anton Shepelev   
   Re: Custom window functions   
   23 May 23 20:56:56   
   
   From: esquel@sommarskog.se   
      
   Anton Shepelev (anton.txt@g{oogle}mail.com) writes:   
   > Does MSSQL support custom window functions?  For example,   
   > suppose I want to implement exponential smoothing in .NET   
   > and register it as a window function in MSSQL -- is that   
   > possible?   
   >   
      
   Depends on what you want to achieve. This works:   
      
      SELECT object_id, name,   
             dbo.integerlist(column_id) OVER(PARTITION BY object_id)   
      FROM   sys.columns   
      ORDER BY object_id, column_id   
      
   dbo.integerlist is a user-defined aggegrate implemented in C#.   
      
   But when I tried:   
      
      SELECT object_id, name,   
             dbo.integerlist(column_id) OVER(PARTITION BY object_id   
                ORDER BY column_id ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)   
      FROM   sys.columns   
      ORDER BY object_id, column_id   
      
   I got   
      
      Msg 156, Level 15, State 1, Line 3   
      Incorrect syntax near the keyword 'ORDER'.   
      
   The error is a little surprising. But presumably there are different parse-   
   trees for built-in and user-defined functions. And supposedly when they   
   introduced windowed aggregates in SQL 2012, they only updated the parse   
   tree for tbe built-ins. Which opens the question what would happen if   
   they fixed the parser...   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca