Calculate the Difference of two Weeek numbers

  • This will need to be tested with many more rows/conditions - but should get you started:

    SELECT iif(B1 < A1, B1+A1+(max(A1) over()-A1), B1) - A1 FROM CTE

    I assumed you wanted a positive number...

     

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • . Did you know there's an ISO 8601 standard for the week within a year display format of the date? It looks like "yyyyW[0-5][0-9]-[0-7]", where "yyyy" is the calendar year, followed by a W as punctuation, followed by 01 to 52 or 53 for the number of the week within the year, a – as punctuation, followed by the day within that week (1=Monday, 7= Sunday). You can download calendars in this format off the Internet a little searching. It's popular in Scandinavian countries. There is no need to invent your own temporal system. You also have a serious design flaw in that a single temporal event is represented in two columns; this violates First Normal Form which says a column must be atomic and not split like this.

    Please post DDL and follow ANSI/ISO standards when asking for help. 

Viewing 2 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply