Our client is in the business of fabricating soap. One feature of our accounting suite is keeping track of all their cooking sessions (they have a production line dedicated for that and it is called kettle).
A database table called ProductLineForm handles immediate data for each session.
A session can be NOT STARTED, STARTED and ENDED. Two columns StartDate and EndDate of type DATETIME must always be of valid values all the time.
NOT STARTED should have both start and end dates to have the SQL minimum date value.
STARTED should have its end date still using the minimum value while the start date will get the started date.
ENDED must be that the start date is always equal or earlier than the end date.
I need to implement this rule to the table. Here is the check constraint applied.
ALTER TABLE ProductLineForm
ADD CONSTRAINT ProductLineForm__Date__Rule
CHECK
(
(DATEDIFF(d,StartDate,’1753-01-01′) = 0 AND DATEDIFF(d,EndDate,’1753-01-01′)=0)
OR (DATEDIFF(d,’1753-01-01′, StartDate) > 0 AND DATEDIFF(d,EndDate,’1753-01-01′)=0)
OR DATEDIFF(d, StartDate, EndDate) >= 0
)



