Check constraint with condition
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Check constraint with condition

  1. #1
    Join Date
    Apr 2001
    Location
    London
    Posts
    725

    Check constraint with condition

    Hello All.

    I need a constraint against records created/amended that have an invoicenumber beginning with CN%, ensure the analysiscode is not like the value ' %'. As some people are entering spaces in the analysiscode.

    Anyway this logic does not work ...

    alter table invoicesalesanalys
    add constraint check_anaLYSISCODE
    check (ANALYSIS1CODE not like ' %' where invoicenumber like 'CN%')

    I need a way of tackling it - can anyone help?

    Thanks
    Once you have eliminated all of the impossible,
    whatever remains however improbable,
    must be true.

  2. #2
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    I'd think that something like ...
    Code:
    check (NOT (ANALYSIS1CODE like ' %' and invoicenumber like 'CN%'))
    ... or ...
    Code:
    check (ANALYSIS1CODE not like ' %' or invoicenumber not like 'CN%')
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

  3. #3
    Join Date
    Apr 2001
    Location
    London
    Posts
    725
    Hmm...

    Yes the AND logic works correctly.

    basically check those 2 conditions are not true.

    Thankyou very much.

    Suresh
    Once you have eliminated all of the impossible,
    whatever remains however improbable,
    must be true.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width