On Wed, 29 Oct 2008 15:33:07 -0700 (PDT), bob laughland wrote:
Quote:
>Hi All,
>
>I have another SQL question, and this one is going to be difficult to
>explain.
|
(snip)
Hi Bob,
First - in the future, please post CREATE TABLE and INSERT statements,
as knowing the table structure makes it easier to understand the problem
and having test data makes it easier to test. And I don't have the time
to manually create a table or enter test data, so you (who needs the
question answered) are the one who should invest time to spoonfeed me
what I need to help you. :)
Second - based on your description, I fail to see where the optional
values weigh in. If a rowid has all the required values, then you want
to return it whether the optional values are or are not present. So I'd
say ditch the optional values and loook at the required values only.
Third - reread the reply by Joe Celko to your first question. He
describes two methods of relational division, one with nested subqueries
and another one with GROUP BY and HAVING. The extra requirement
introduced here is easy to implement if you use this second version, as
all it takes is one extra line in the HAVING clause:
AND SUM(CASE WHEN changed = 1 THEN 1 ELSE 0 END) >= 1
If changed is some numeric type, you could even simplify this to
AND SUM(changed) >= 1
--
Hugo Kornelis, SQL Server MVP
My SQL Server blog:
http://sqlblog.com/blogs/hugo_kornelis