Search code examples
sqlsql-serverfiscal

create fiscal week number


How can I put the below logic into a format SQL Server will use to create a fiscal week number ?

if (datepart(week,getdate())-4) <= 0  then (datepart(week,getdate())+49) else (datepart(week,getdate())-4)

Solution

  • The CASE Statement should work:

    CASE 
        WHEN (datepart(week,getdate())-4) <= 0
            THEN datepart(week,getdate())+49
        ELSE
            datepart(week,getdate())-4
    END