Get Week Numbers for Quarter and Month in SQL...

I needed to get the Week Number for the Month and the Quarter for a BI Application.
I was able to retrieve it using the below query.

SELECT DATEDIFF(WEEK, DATEADD(MONTH, DATEDIFF(MONTH, 0, '2012-03-17'), 0), '2012-03-17') +1 AS WeekNoMonth,DATEDIFF(WEEK, DATEADD(QUARTER, DATEDIFF(QUARTER, 0, '2012-03-17'), 0), '2012-03-17') +1 AS WeekNoQuarter

The results are WeekNoMonth=3 and WeekNoQuarter=11

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete

How to run UPDATE/INSERT/DELETE Statements on Azure SQL Database in Microsoft Fabric Notebook...

You can run UPDATE/INSERT/DELETE Statements on Azure SQL Database in Microsoft Fabric Notebook using Python SQL Driver - pyodbc.  For the Fa...