check
= (
=A0 =A0 (
=A0 =A0 =A0 =A0 ( a1 is not null and a2 is not null )
= =A0 =A0 =A0 =A0 or
=A0 =A0 =A0 =A0 ( a1 is null and a2 is null )
=A0 =A0 )
=A0 =A0 and=A0 =A0 (
=A0 =A0 =A0 =A0 ( b1 is not null and b2 is not null )
=A0= =A0 =A0 =A0 or
=A0 =A0 =A0 =A0 ( b1 is null and b2 is null )
=A0 =A0= )
=A0 =A0 and ( a1 is not null or b1 is not null )=A0 =A0=
)

(we can test only a1/b1 here because the "o= ther member of the pair" has already been tested earlier).

On Mon, May 7, 2012 at 9:36 AM, Rick Hillegas wrote:
On 5/7/12 5:14 AM, Biene_Majo@yahoo.de wrote:
Hi,

i have a table with 4 columns:
A1
A2
B1
B2
i now need something like this (in relation to null values):
(A1 AND A2) OR (B1 AND B2)

So that if A1 is not null A2 must not be null and the other way around (so = if A2 is not null A1 is not allowed to be null).
The same for B1 and B2.
And at least one of the 2 pairs must not be null.

Can someone tell me if this is possible or how?

Thanks for any suggestions / answers

Biene Majo

Hi Biene,

What you describe sounds like a CHECK constraint to me. Not sure that I und= erstand the exact condition you're trying to catch, but something like = the following might work for you:

create table t
(
=A0 =A0a1 int,
=A0 =A0a2 int,
=A0 =A0b1 int,
=A0 =A0b2 int,

=A0 =A0check
=A0 =A0(
=A0 =A0 =A0 =A0(
=A0 =A0 =A0 =A0 =A0 =A0( a1 is not null and a2 is not null )
=A0 =A0 =A0 =A0 =A0 =A0or
=A0 =A0 =A0 =A0 =A0 =A0( a1 is null and a2 is null )
=A0 =A0 =A0 =A0)
=A0 =A0 =A0 =A0and
=A0 =A0 =A0 =A0(
=A0 =A0 =A0 =A0 =A0 =A0( b1 is not null and b2 is not null )
=A0 =A0 =A0 =A0 =A0 =A0or
=A0 =A0 =A0 =A0 =A0 =A0( b1 is null and b2 is null )
=A0 =A0 =A0 =A0)
=A0 =A0)
);

Hope this helps,
-Rick

--f46d04428f10d871df04bf71e5e0--