Search code examples
sqlt-sqlazureodata

DAYOFWEEK function for SEDE?


The specifications on SQL Azure mention ODBC date and time functions, namely to transform a date to weekday.

Currently, using DAYOFWEEK results in an error message:

SELECT DAYOFWEEK(LastActivityDate) FROM Posts Limit 1;

Error: 'DAYOFWEEK' is not a recognized built-in function name.


Solution

  • DAYOFWEEK is a MySQL function (likewise for LIMIT) - Azure uses Microsoft's TSQL functionality - you want DATEPART:

    SELECT TOP 1
           DATEPART(dw, LastActivityDate) 
      FROM Posts
    

    Reference: