Constraints

  • Hi -

    is it possible to have a constraint on two columns whichs uses "between"?

    (if date inserted between DateField1 and DateField2 then fail)

    for example, product XYZ's value at $4 starts on 4/1/2009 and ends on 4/30/2009.

    product XYZ's value at $5 must start on 5/1/2009, i dont want anyone to enter a record that has an April 2009 date.

    thanks!

  • Not sure if that can be done with a constraint. Pretty easy to do with a trigger.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • This doesn't look like something you need a constraint for as much as looking at it differently. What you describe fits a design that would use a ValidFrom, ValidTo design, or use effective dates to ensure that the correct Product record is selected based on the date of the order.

  • You can create a scalar UDF which gets the ProductId, DateFiel1 and DateField2 and checks if another Product already exists. Then you can use the UDF in your CHECK constraing.

    Greets

    Flo

  • Florian Reischl (5/2/2009)


    You can create a scalar UDF which gets the ProductId, DateFiel1 and DateField2 and checks if another Product already exists. Then you can use the UDF in your CHECK constraing.

    Greets

    Flo

    'zactly.

    --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 5 posts - 1 through 4 (of 4 total)

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