Need help with Cut off time in SQL

  • Hi,

    Need this DAX covert SQL T-SQL.

    Ticket Cutoff Status =

    VAR TimeOnly = TIME(HOUR([Remedy Submitted Date]), MINUTE([Remedy Submitted Date]), SECOND([Remedy Submitted Date]))

    RETURN

    SWITCH(

    TRUE(),

    TimeOnly < TIME(13, 0, 0), "Prior to Cutoff",

    TimeOnly >= TIME(13, 0, 0) && TimeOnly <= TIME(14, 0, 0), "Grey Zone",

    TimeOnly > TIME(14, 0, 0), "Prior the Cutoff"

    )

    The Submit_Date is in EPOCH time/date.

    I was able to figure some out for other columns but for time cut off I cannot figure that out!

    For example:

    CASE WHEN DATEDIFF(day, DATEADD("hh", -5, DATEADD("S", Submit_Date, 'January 1, 1970')),DATEADD("hh", -5, DATEADD("S", Completed_Date, 'January 1, 1970'))) >= 30 Then 'Yes'

    WHEN DATEDIFF(day, DATEADD("hh", -5, DATEADD("S", Submit_Date, 'January 1, 1970')),DATEADD("hh", -5, DATEADD("S", Completed_Date, 'January 1, 1970'))) < 30 Then 'No'

    END AS 'Over 30 Days'

    So what I need is T-SQL code for:

    Ticket submitted before 1 pm = 'Prior to Cutoff'

    Between 1pm and 2 pm = 'Grey Zone'

    After 2 pm = 'Past Cutoff'

    Thank you,

    Holly

     

     

     

     

  • hollyanneu2 wrote:

    Hi,

    Need this DAX covert SQL T-SQL.

    Ticket Cutoff Status = VAR TimeOnly = TIME(HOUR([Remedy Submitted Date]), MINUTE([Remedy Submitted Date]),

    SECOND([Remedy Submitted Date])) RETURN SWITCH( TRUE(), TimeOnly < TIME(13, 0, 0), "Prior to Cutoff",

    TimeOnly >= TIME(13, 0, 0) && TimeOnly <= TIME(14, 0, 0), "Grey Zone"

    , TimeOnly > TIME(14, 0, 0), "Prior the Cutoff" )

    You do realize that the last "Prior the Cutoff" is actually after the cutoff, right?

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

  • yes...there is a slight change to the policy. No worries.

    Thank you for pointing that out and asked! 🙂

     

     

     

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

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