conversion of excel formula to case statement in tsql

  • Hi  all,

    need your help on conversion of excel formula into case statement. i tried but missing only one case. below is excel formula:

    =IF(AND(Q141="EndOfDay", AD141="EndOfDay",V141=""),8,

    MIN(8,

    IF(OR(Q141="EndOfDay"), 0,

    IF( AND( OR(Q141= "Paused", Q141= "PlannedBreak", Q141= "Completed"), AD141="EndOfDay" ),

    MAX(0,T141-7),

    IF(Z141="",0,

    (ROUNDDOWN(Z141/10000,0)+(ROUNDDOWN(RIGHT(Z141,4)/100,0)/60)+(ROUNDDOWN(RIGHT(Z141,2),0)/(60*60)) )

    - (ROUNDDOWN(J141/10000,0)+(ROUNDDOWN(RIGHT(J141,4)/100,0)/60) +(ROUNDDOWN(RIGHT(J141,2),0)/(60*60)) )

    )))

    ))

     

    Thanks

    Abhas

  • Which part of this do you need assistance with?

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Abhas wrote:

    Hi  all,

    need your help on conversion of excel formula into case statement. i tried but missing only one case. below is excel formula:

    =IF(AND(Q141="EndOfDay", AD141="EndOfDay",V141=""),8, MIN(8, IF(OR(Q141="EndOfDay"), 0, IF( AND( OR(Q141= "Paused", Q141= "PlannedBreak", Q141= "Completed"), AD141="EndOfDay" ), MAX(0,T141-7), IF(Z141="",0, (ROUNDDOWN(Z141/10000,0)+(ROUNDDOWN(RIGHT(Z141,4)/100,0)/60)+(ROUNDDOWN(RIGHT(Z141,2),0)/(60*60)) ) - (ROUNDDOWN(J141/10000,0)+(ROUNDDOWN(RIGHT(J141,4)/100,0)/60) +(ROUNDDOWN(RIGHT(J141,2),0)/(60*60)) ) )))

    ))

    Step one would be to post the column names that you're using above.  For example, what's in Column "Z"???

    --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)

  • It would help if you showed some work. The general flow would be something like:

    SELECT
    CASE WHEN Q141 = 'EndofDay' AND AD141 = 'EndofDay' AND V141 = '' THEN 8
    ELSE xx
    END

    RoundDown should be ROUND() in T-SQL. Min() is an aggregate, so that might cause some issues in a query, but hard to tell from here.

  • Abhas wrote:

    Hi  all,

    need your help on conversion of excel formula into case statement. i tried but missing only one case. below is excel formula:

    =IF(AND(Q141="EndOfDay", AD141="EndOfDay",V141=""),8, MIN(8, IF(OR(Q141="EndOfDay"), 0, IF( AND( OR(Q141= "Paused", Q141= "PlannedBreak", Q141= "Completed"), AD141="EndOfDay" ), MAX(0,T141-7), IF(Z141="",0, (ROUNDDOWN(Z141/10000,0)+(ROUNDDOWN(RIGHT(Z141,4)/100,0)/60)+(ROUNDDOWN(RIGHT(Z141,2),0)/(60*60)) ) - (ROUNDDOWN(J141/10000,0)+(ROUNDDOWN(RIGHT(J141,4)/100,0)/60) +(ROUNDDOWN(RIGHT(J141,2),0)/(60*60)) ) )))

    ))

    Thanks

    Abhas

    Let's rephrase this, you need a bit of alchemy, turning turd to gold

    😎

    First of all, try to format the statement properly, secondly, this statement does not parse as it is incomplete

Viewing 5 posts - 1 through 4 (of 4 total)

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