Help With Default Value

  • I wonder if any can help me. I want the default due date for a sales order to be today's date if it is entered before 2:00PM, if after, the default due date is the next business date. Any help will be appreciated. Thuan Pham

  • if  substring(convert(varchar(20), getdate(), 120), 12, 2) < 14

        @due_date = getdate()

    else

        @due_date = dateadd(dd, 1, getdate()

     

  • Do you want the time included in the default, or not?  All of the posts, so far, include time.

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

  • If you are using SQL2000 then you can use User defined functions. There you can write whatever logic you want. --Thanks Vilas

  • Just add ten hours to the time the order was placed. That will throw it into the next day.

     

    declare @order_date datetime

    declare @deliver_date datetime

    set @deliver_date = dateadd(hh, 10, @order_date)

    (Using a user defined function may be costly in terms of processing time unless you are processing one order at a time.)

  • Do you want the next date if it's a weekend day? Your original post said business date. If you add ten hours to the time of orders after 2 pm, that sets the date to the next contiguous date, but the time might be in the wee hours. Is that what you need?

    There is no "i" in team, but idiot has two.
  • Thank you for all your help.

    Thuan Pham

  •  

    declare @Date datetime

    select @Date = getdate()--dateadd(hh, 0, getdate())

    select

     cast(Case

      When datepart(hh, @Date) < 14

       then convert(varchar(12), @Date, 101)

       Else

        Case datepart(dw, @Date + 1)

         when 1 then convert(varchar(12), @Date+ 1, 101)

         When 7 then convert(varchar(12), @Date+ 3, 101)

         Else @Date

        END

     END as datetime)

     

    Signature is NULL

Viewing 8 posts - 1 through 7 (of 7 total)

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