Every Named Calculation makes error!

  • Hi

    After I create a Named Calculation,I can't Explore Data. I get Error:

    TITLE: Microsoft Visual Studio

    ------------------------------

    Input string was not in a correct format.

    ------------------------------

    BUTTONS:

    OK

    ------------------------------

    1

    2

    • This topic was modified 4 years, 1 month ago by  elham_gh.
  • Thanks for posting your issue and hopefully someone will answer soon.

    This is an automated bump to increase visibility of your question.

  • I can't help you with your Visual Studio problem because I don't use it.  I can tell you, though, that your formula for age in years is incorrect simply because of the way DATEDIFF works.  You need to use something like the following...

    ALTER FUNCTION [Util].[AgeInYears]
    (
    @StartDT DATETIME, --Date of birth or date of manufacture or start date.
    @EndDT DATETIME --Usually, GETDATE() or CURRENT_TIMESTAMP but
    --can be any date source like a column that has an end date.
    )
    RETURNS TABLE WITH SCHEMABINDING AS
    RETURN
    SELECT AgeInYears =
    DATEDIFF(yy, @StartDT, @EndDT)
    - CASE --If anniversary date hasn''t happended yet this year, subtract 1.
    WHEN DATEADD(yy, DATEDIFF(yy, @StartDT, @EndDT), @StartDT) > @EndDT
    THEN 1
    ELSE 0
    END
    ;

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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