March 26, 2003 at 8:58 pm
Field1 can be several values depending on the status of the record, C, X, B, R etc. However I don't want my users to change this record to a B unless the document field has a good (not dummy) number inserted. How do I write the check constraint?
I tried (field1 = 'B' and field2 <> 0000) But that doesn't allow my users to use the C, X or R values.
What am I missing?
Michelle
March 26, 2003 at 11:36 pm
try (field1 <> 'B' or field2<>0000)
March 26, 2003 at 11:45 pm
Use IN operator
Create Table xXx
( Field1 vachar(10), Field2 varchar(10),
Check ( Field1 IN ('C', 'X', 'B', 'R') And
Field2 <> 0000 ))
March 27, 2003 at 5:43 am
If they choose C, X, or R then the field2 can be 0000. It is only when they choose B that field2 must be a real document number.
Thanks
Michelle
March 27, 2003 at 6:22 am
try:
CHECK((Field1 IN ('C', 'X', 'R')) Or (
Field1 = 'B' AND Field2 <> 0000))
March 27, 2003 at 7:49 am
me thinks you did not try my first suggestion...?
>> (field1<>'B' or field2<>0000)
jpipes response is probably more understandalbe, but mine is shorter. and it would allow you to add other codes that don't require a valid # in field2. then again, maybe I'm off my rocker and should actually try testing code suggestions before submitting them.
March 27, 2003 at 8:08 am
Completely agree with joshcsmith13: his suggestion will be much more maintainable... 🙂
March 27, 2003 at 8:17 am
My apologies joshcsmith13, my tired brain read your suggestion as a way to never have the 'B' in field1. I am awake now and I understand it. I did use jpipes suggestion and that worked but I agree that I like joshcsmith13's better also.
Thank you everyone!
Michelle
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply