Need help with complex SQL query (Sybase)

Hello,

I have three tables.

I need an SQL query (preferably Sybase) that will return all of the stringID values of table B where the following conditions exist:

  \(1\) B.intID = A.intID
  \(2\) B.intID != C.intID 
      or \(B.intID = C.intID and
          \(C.v1 = 0 or C.v2 = 0\)\)

Here are the table defs:

create table A (
intID int
}

create table B (
intID int,
stringID varchar(15)
)

create table C (
stringID varchar(15),
v1 int,
v2 int
)

Thanks for any input,
Elizabeth

(1) B.intID = A.intID
(2) B.stringID != C.stringID
or (B.stringID = C.stringID and
(C.v1 = 0 or C.v2 = 0))

Not familiar with Sybase but you might want to try something like this.

 
SELECT B.stringID FROM A,B,C WHERE B.intID = A.intID AND ((B.stringID <> C.stringID) OR ((B.stringID = C.stringID) AND (C.v1 = 0 OR C.v2 = 0)));