Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Microsoft SQL Server > Re: SQL Select ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 4 Topic 11026 of 11517
Post > Topic >>

Re: SQL Select All Items where one meets the criteria

by ckauvar@[EMAIL PROTECTED] May 8, 2008 at 11:17 AM

On May 8, 1:20=A0pm, "Plamen Ratchev" <Pla...@[EMAIL PROTECTED]
> wrote:
> Here is one way:
>
> SELECT P.people_code_id, G.giving_amount, G.fiscal_year
> FROM People AS P
> JOIN GivingSummary AS G
> =A0 ON P.people_code_id =3D G.people_org_code_id
> WHERE EXISTS (SELECT *
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0FROM GivingSummary AS G2
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0WHERE G2.people_org_code_id
=3D=
 G.people_org_code_id
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0AND G2.giving_amount
>=
=3D 500
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0AND G2.fiscal_year <>
'=
');
>
> HTH,
>
> Plamen Ratchevhttp://www.SQLStudio.com

Hi,

Thanks for the response.  That is perfect.  This leads to one more
question.  Now that I am selecting the right group of people and
gifts, I need the select statement to adjust based on the number of
years the users want to re****t on.  I've created a prompt where the
user enters a starting fiscal year.  I then need to pull individuals
who have given a gift of $500 or more in any year starting with the
fiscal year the user entered.  So, somehow I need to tell the query to
look to the user entered fiscal year and then run the exists statement
for years greater than or equal to that year.

For example, in the example I gave above the donor gives the following
gifts:
in 2006 they give $250
in 2007 they give $550
in 2008 they give $50

If at the prompt the user enters 2006, then all 3 gifts above would
appear.  If at the prompt the user enters 2008, then the person would
not appear on the list because they do not have a gift above $500 in
the time period requested.

I tried adding in something along the lines of below, but it doesn't
seem to be working.  Any suggestions?

WHERE     EXISTS (SELECT *
                     FROM GivingSummary AS G2
                     WHERE G2.people_org_code_id =3D
GIVINGSUMMARY.people_org_code_id
                         AND G2.giving_amount >=3D 500
                         AND G2.fiscal_year <> ''
                         AND G2.FISCAL_YEAR >=3D @[EMAIL PROTECTED]
)
 




 4 Posts in Topic:
SQL Select All Items where one meets the criteria
ckauvar@[EMAIL PROTECTED]  2008-05-08 09:05:55 
Re: SQL Select All Items where one meets the criteria
"Plamen Ratchev"  2008-05-08 13:20:44 
Re: SQL Select All Items where one meets the criteria
ckauvar@[EMAIL PROTECTED]  2008-05-08 11:17:34 
Re: SQL Select All Items where one meets the criteria
"Plamen Ratchev"  2008-05-08 16:24:35 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Dec 2 22:05:47 CST 2008.