Computed Column: # Days in YearMonth Month

  • Hi Gang-

    I keep getting "error validating the formula" for a computed column I'd like to create. I have an INT column called YearMonth with values you'd expect (201511, 201512, 201601, etc.). I'd like a computed column to display the number of days in each YearMonth. The following works in a SELECT statement but not in a computed column:

    DATEDIFF(day, (CAST((YearMonth*100)+1 AS CHAR(8))), (DATEADD(month, 1, CAST((YearMonth*100)+1 AS CHAR(8)))))

    What rule am I unwittingly violating here?

    Thanks!


    "If I had been drinking out of that toilet, I might have been killed." -Ace Ventura

  • As I recall that usually happens when using the SSMS GUI to create the column under some conditions (bugs, mostly, if memory serves).

    Have you tried adding the column with TSQL?

    Cheers!

  • You are correct, thank you! That was frustrating, really appreciate your help!


    "If I had been drinking out of that toilet, I might have been killed." -Ace Ventura

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

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