check constraint expression prob

  • I am trying to add a check constraint to my table:

    alter table ads

    ADD CONSTRAINT

    CK_ads_1 (not([ad_status] = 'approved, awaiting artwork files' and [approved_snapshot_id] = null))

    ie approved_snapshot_id cant be null when the ad_status is 'approved, awaiting artwork files'

    the constraint seems to 'save' properly, however the constraint just doesn't work. Is it because constraints ignore columns with null values? If so, is there an alternative way of solving my problem. Thanks.

  • try "is null" instead of "= null"

    alter table ads

    ADD CONSTRAINT

    CK_ads_1 (not([ad_status] = 'approved, awaiting artwork files' and [approved_snapshot_id] is null))

    if( null = null )

        print 'null = null'

    if( null is null )

        print 'null is null'

    /rockmoose


    You must unlearn what You have learnt

  • thanks rockmoose, works fine now  

     

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply