'strftime' is not a recognized built-in fu

2019-03-02 13:29发布

I am using Microsoft SQL Database Management Studio and it will not allow me to use the strftime() function to run a query. I have to create a table by months with new users and unsubscribers for each month.

This is what I had essentially which creates the error:

SELECT strftime('%m', createddate) AS 'Month', COUNT(createddate) AS 'Subscribers',
       COUNT(dateunsubscribed) AS 'UNsubscribers'
FROM subscriber
GROUP BY 1
ORDER BY 1;

how else could I run this query without strftime() or how can I get strftime() to work?

1条回答
男人必须洒脱
2楼-- · 2019-03-02 14:08

strftime is a function, and isn't available in Microsoft's .

For this simple usecase (extracting a month from a date), you could user month:

SELECT   MONTH(createddate) AS [Month], 
         COUNT(createddate) AS [Subscribers],
         COUNT(dateunsubscribed) AS [UNsubscribers]
FROM     subscriber
GROUP BY 1
ORDER BY 1;

EDIT:
To address the question in the comment, the group by clause doesn't take an ordinal like the order by clause does. You'll need to specify the expression you want to group by:

SELECT   MONTH(createddate) AS [Month], 
         COUNT(createddate) AS [Subscribers],
         COUNT(dateunsubscribed) AS [UNsubscribers]
FROM     subscriber
GROUP BY 1
ORDER BY MONTH(createddate);
查看更多
登录 后发表回答