tags:

views:

29

answers:

1

Hi, I have a problem with my code. As you can see i Try to have a sort of CHECK constraint using two columns in the same table but seems does not work. My need is to accept value in EffectiveEndDate only if they are > that EffectiveStartDate.

Any idea how to solve it? thanks for your support! :-)

CREATE TABLE dbo.Test 
(   
EffectiveStartDate  dateTime2(2)        NOT NULL,
EffectiveEndDate    dateTime2(2)        NOT NULL
    CONSTRAINT CK_CmsSponsoredContents_EffectiveEndDate CHECK (EffectiveEndDate > EffectiveStartDate),
);
+4  A: 

You've got a comma in the wrong spot:

CREATE TABLE dbo.Test(  
  EffectiveStartDate dateTime2(2) NOT NULL,
  EffectiveEndDate   dateTime2(2) NOT NULL,  -- added missing comma
  CONSTRAINT CK_CmsSponsoredContents_EffectiveEndDate CHECK (EffectiveEndDate>EffectiveStartDate)
)

Removed a comma at the end of the check constraint declaration.

OMG Ponies
thanks I really did not notice that, now is working thanks
GIbboK