开发者

Create a constraint in a field depending of another field

I have a table T1 with three field:

  • id integer
  • Vocation integer : VOCATION = 1 or 2 or 3 or 4 or 5
  • TYPE integer : TYPE = 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8

TYPE depend on VOCATION. For example if 开发者_开发问答VOCATION = 1, TYPE should be = 2 or 3 or 4 or 6, other example if VOCATION = 2, TYPE should be = 4 or 5, etc.

I would create a constraint in TYPE that force the value of constraint to be, for example, 4 or 5 if the value of VOCATION is 2, etc.

some idea please

I tried this but it didn't work:

TYPE = contr( !VOCATION!)

def contr(Voc):
    if Voc == 1 :
        return [2, 3, 4, 6]


Perhaps you could utilise the power of Python dictionaries and do the following:

>>> vocdict = {1:[2,3,4,6], 2:[4,5]}
>>> vocdict.get(1)
 [2, 3, 4, 6] 
>>> vocdict.get(2)
 [4, 5]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜