GAA
Mon Apr 10 08:43:02 CDT 2006
This seems so obvious, I'm obviously doing something silly!
Each condition works separately, and conditions 2 and 3 work fine when
condition 1 isn't included. However as soon as I introduce condition 1,
whether it be at the beginning, the middle or the end, it simply does not
return what I expect!
The SelectName, SelectActivity and SelectPurpose variables are selected by
the user from drop-down lists. If only two conditions are used i.e. user only
selects criteria from 2 of the 3 drop-down lists then the correct results are
returned. When the user selects criteria from all 3 drop-down lists, it only
returns results for one of the variables being matched i.e. SelectName.
For example:
Say I select 'Greg Aitken' from the SelectName drop-down list, 'Meeting'
from the SelectActivity drop-down list and 'Teachers' from the SelectPurpose
drop-down list it returns all the records which have 'Greg Aitken' in the
Name field and ignores the other two conditions, even though there definitely
are records that match all 3 criteria.
What am I doing wrong? I'm beginning to think it's not my query but
something else?
Thanks again
Greg
"Stefan B Rusynko" wrote:
> Rewriting won't correct logic assumption errors
> (that your data will match the query)
> But here it is
> (all lines below are on 1 line!)
>
> SELECT * FROM Results WHERE
> (Name='::SelectName::' AND Activity='::SelectActivity::' AND Purpose='::SelectPurpose::')
> OR (Name='::SelectName::' AND Activity='::SelectActivity::')
> OR (Name='::SelectName::' AND Purpose='::SelectPurpose::')
>
> Test each condition separately
> For the 1st one just use
>
> SELECT * FROM Results WHERE
> (Name='::SelectName::' AND Activity='::SelectActivity::' AND Purpose='::SelectPurpose::')
>
> --
>
> _____________________________________________
> SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
> "Warning - Using the F1 Key will not break anything!" (-;
> To find the best Newsgroup for FrontPage support see:
>
http://www.frontpagemvps.com/FrontPageNewsGroups/tabid/53/Default.aspx
> _____________________________________________
>
>
> "GAA" <GAA@discussions.microsoft.com> wrote in message news:A07D60E6-FFE8-47F5-B0BD-A9A67BA084B6@microsoft.com...
> | Thanks Stefan,
> |
> | However I'm obviously still doing something wrong as I still can't get it to
> | work. Can you re-write my original query for me, so I know how it should read?
> |
> | Thanks
> |
> | "Stefan B Rusynko" wrote:
> |
> | > Logic error
> | > - make your 3rd condition the 1st condition
> | >
> | > In any select with OR the 1st criteria met will yield the results
> | > (even if any further tests could also yield results)
> | > And the results are determined from left to right
> | > (so the 1st test that fails, yields an F, determines the test result)
> | > - in your case test 1 and test 2 already have determined the results of test 3 before it is even seen
> | > Look at your code as simple Boolean tests
> | > - below is annotated w/ simple results as XtestT/F meaning results of comparison are True or False
> | >
> | > SELECT * FROM Results
> | > WHERE
> | > (Name='::SelectName::' AND Activity='::SelectActivity::')
> | > (NtestT/F and AtestT/F) which yields T OR F (test1) - say T
> | > OR
> | > (Name='::SelectName::' AND Purpose='::SelectPurpose::')
> | > (NtestT/F and PtestT/F) which yields T OR F (test2) - say T
> | > OR
> | > (Name='::SelectName::' AND Activity='::SelectActivity::' AND Purpose='::SelectPurpose::')
> | > (NtestT/F and AtestT/F and PtestT/F)
> | > is the same as ( test1T/F and PtestT/F ) which yields T OR F (test 3)
> | > - and by this time either test1 or test2 has yielded T so they would have been selected for results
> | > (or if test1 has yielded F, test 3 will always yield F)
> | >
> | > --
> | >
> | > _____________________________________________
> | > SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
> | > "Warning - Using the F1 Key will not break anything!" (-;
> | > To find the best Newsgroup for FrontPage support see:
> | >
http://www.frontpagemvps.com/FrontPageNewsGroups/tabid/53/Default.aspx
> | > _____________________________________________
> | >
> | >
> | > "GAA" <GAA@discussions.microsoft.com> wrote in message news:2EB1B579-0F09-40B7-8227-F0D26FB7C596@microsoft.com...
> | > |I have written a Custom Query using the Database Results Wizard as follows:
> | > |
> | > | SELECT * FROM Results WHERE (Name = '::SelectName::' AND Activity =
> | > | '::SelectActivity::') OR (Name = '::SelectName::' AND Purpose =
> | > | '::SelectPurpose::') OR (Name = '::SelectName::' AND Activity =
> | > | '::SelectActivity::' AND Purpose = '::SelectPurpose::')
> | > |
> | > | The first two parts of this work fine and return the correct results if only
> | > | two criteria option are selected, however when all three criteria selection
> | > | are selected the the results returned are incorrect, it seems to only
> | > | recognise and match the Name part.
> | > |
> | > | Any ideas?
> | >
> | >
> | >
>
>
>