Query Impossible?

C

Claudette Hennessy

I have hit a wall with this..The relevant table data is:

Dealer Year
Dealer1 2008
Dealer2
Dealer3 2009
Dealer4 2009
Dealer5
Dealer6 2008
....
The desired output for 2008 criteria in the query would be
Dealer1 2008
Dealer2
Dealer3
Dealer4
Dealer5
Dealer6 2008

The desired output for 2009 criteria would be
Dealer1
Dealer2
Dealer3 2009
Dealer4 2009
Dealer5
Dealer6



Is this impossible? It seems so simple. Any help is much appreciated.
Claudette
 
M

Michel Walsh

SELECT dealer , iif( [year]=[criteria value], [year], null)
FROM tableName



Vanderghast, Access MVP
 
B

Bob Barrows [MVP]

Claudette said:
I have hit a wall with this..The relevant table data is:

Dealer Year
Dealer1 2008
Dealer2
Dealer3 2009
Dealer4 2009
Dealer5
Dealer6 2008
...
The desired output for 2008 criteria in the query would be
Dealer1 2008
Dealer2
Dealer3
Dealer4
Dealer5
Dealer6 2008

The desired output for 2009 criteria would be
Dealer1
Dealer2
Dealer3 2009
Dealer4 2009
Dealer5
Dealer6

You will need to use the iif() function:

select Dealer, iif([Year]=[Enter Year],[Year],null) as DealerYear
from table
 
C

Claudette Hennessy

Thank you, tried lots of approaches but never thought of IIF, almost
there..should have included the case that:

Dealer Year
Dealer1 2008
Dealer2
Dealer3 2009
Dealer3 2008
Dealer4
Dealer5 2009
Dealer6

So: using IIf([ShowYear]=[criteria value],[ShowYear],Null) results in

Dealer Year
Dealer1 2008
Dealer2
Dealer3
Dealer3 2008
Dealer4
Dealer5
Dealer6

Can I get rid of that extra Dealer3?

Claudette

Bob Barrows said:
Claudette said:
I have hit a wall with this..The relevant table data is:

Dealer Year
Dealer1 2008
Dealer2
Dealer3 2009
Dealer4 2009
Dealer5
Dealer6 2008
...
The desired output for 2008 criteria in the query would be
Dealer1 2008
Dealer2
Dealer3
Dealer4
Dealer5
Dealer6 2008

The desired output for 2009 criteria would be
Dealer1
Dealer2
Dealer3 2009
Dealer4 2009
Dealer5
Dealer6

You will need to use the iif() function:

select Dealer, iif([Year]=[Enter Year],[Year],null) as DealerYear
from table

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
 
B

Bob Barrows [MVP]

You will need to group the results from the first query and return the
max dealeryear:

Select Dealer,Max(DealerYear) As FilteredYear FROM
(select Dealer, iif([Year]=[Enter Year],[Year],null) as DealerYear
from table) as q
group by Dealer

Claudette said:
Thank you, tried lots of approaches but never thought of IIF, almost
there..should have included the case that:

Dealer Year
Dealer1 2008
Dealer2
Dealer3 2009
Dealer3 2008
Dealer4
Dealer5 2009
Dealer6

So: using IIf([ShowYear]=[criteria value],[ShowYear],Null) results in

Dealer Year
Dealer1 2008
Dealer2
Dealer3
Dealer3 2008
Dealer4
Dealer5
Dealer6

Can I get rid of that extra Dealer3?

Claudette

Bob Barrows said:
Claudette said:
I have hit a wall with this..The relevant table data is:

Dealer Year
Dealer1 2008
Dealer2
Dealer3 2009
Dealer4 2009
Dealer5
Dealer6 2008
...
The desired output for 2008 criteria in the query would be
Dealer1 2008
Dealer2
Dealer3
Dealer4
Dealer5
Dealer6 2008

The desired output for 2009 criteria would be
Dealer1
Dealer2
Dealer3 2009
Dealer4 2009
Dealer5
Dealer6

You will need to use the iif() function:

select Dealer, iif([Year]=[Enter Year],[Year],null) as DealerYear
from table

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get
a quicker response by posting to the newsgroup.
 
C

Claudette Hennessy

You nailed it..thank you very, very much.

Claudette
Bob Barrows said:
You will need to group the results from the first query and return the
max dealeryear:

Select Dealer,Max(DealerYear) As FilteredYear FROM
(select Dealer, iif([Year]=[Enter Year],[Year],null) as DealerYear
from table) as q
group by Dealer

Claudette said:
Thank you, tried lots of approaches but never thought of IIF, almost
there..should have included the case that:

Dealer Year
Dealer1 2008
Dealer2
Dealer3 2009
Dealer3 2008
Dealer4
Dealer5 2009
Dealer6

So: using IIf([ShowYear]=[criteria value],[ShowYear],Null) results in

Dealer Year
Dealer1 2008
Dealer2
Dealer3
Dealer3 2008
Dealer4
Dealer5
Dealer6

Can I get rid of that extra Dealer3?

Claudette

Bob Barrows said:
Claudette Hennessy wrote:
I have hit a wall with this..The relevant table data is:

Dealer Year
Dealer1 2008
Dealer2
Dealer3 2009
Dealer4 2009
Dealer5
Dealer6 2008
...
The desired output for 2008 criteria in the query would be
Dealer1 2008
Dealer2
Dealer3
Dealer4
Dealer5
Dealer6 2008

The desired output for 2009 criteria would be
Dealer1
Dealer2
Dealer3 2009
Dealer4 2009
Dealer5
Dealer6


You will need to use the iif() function:

select Dealer, iif([Year]=[Enter Year],[Year],null) as DealerYear
from table

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get
a quicker response by posting to the newsgroup.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Open Form is cancelled 9
Union Crosstab Queries 1
SQL- How to delete records based on QUERY ? 5
Peculiar Behavior of Query 2
functions in criteria 5
transpose query 5
joins pls help 1
JOins pls help 4

Top