Subject | Re: [ib-support] change condition i WHERE clause |
---|---|
Author | Svein Erling Tysvær |
Post date | 2002-08-07T08:51:42Z |
Hi Jenny!
This is a simple one - at least as long as speed is not an issue:
SELECT Code FROM Supro, Person
WHERE (person.postal1 BETWEEN Supro.P1 AND Supro.P2 or
(person.postal1 IS NULL and
person.postal2 BETWEEN Supro.P1 AND Supro.P2))
AND person.personid = 6789
though I don't quite like that way of joining tables and would advice you
to at least try
SELECT Code FROM Person
WHERE EXISTS(SELECT 1 FROM Supro
WHERE person.postal1 BETWEEN Supro.P1 AND Supro.P2 or
(person.postal1 IS NULL and
person.postal2 BETWEEN Supro.P1 AND Supro.P2))
AND person.personid = 6789
(if code is from the table Person)
or (if code is from the table Supro - I fear this one could be slow)
SELECT Code FROM Supro
WHERE EXISTS(SELECT 1 FROM Person
WHERE (person.postal1 BETWEEN Supro.P1 AND Supro.P2 or
(person.postal1 IS NULL and
person.postal2 BETWEEN Supro.P1 AND Supro.P2))
AND person.personid = 6789)
HTH,
Set
This is a simple one - at least as long as speed is not an issue:
SELECT Code FROM Supro, Person
WHERE (person.postal1 BETWEEN Supro.P1 AND Supro.P2 or
(person.postal1 IS NULL and
person.postal2 BETWEEN Supro.P1 AND Supro.P2))
AND person.personid = 6789
though I don't quite like that way of joining tables and would advice you
to at least try
SELECT Code FROM Person
WHERE EXISTS(SELECT 1 FROM Supro
WHERE person.postal1 BETWEEN Supro.P1 AND Supro.P2 or
(person.postal1 IS NULL and
person.postal2 BETWEEN Supro.P1 AND Supro.P2))
AND person.personid = 6789
(if code is from the table Person)
or (if code is from the table Supro - I fear this one could be slow)
SELECT Code FROM Supro
WHERE EXISTS(SELECT 1 FROM Person
WHERE (person.postal1 BETWEEN Supro.P1 AND Supro.P2 or
(person.postal1 IS NULL and
person.postal2 BETWEEN Supro.P1 AND Supro.P2))
AND person.personid = 6789)
HTH,
Set