Query Question?

G

Gyetko

I've posted an example of the Query results I would like returned from
my Data Source. Basically, I want to have one row for each item, then
have columns for the Months and show the Qty for that Item under the
given Month. I know I can get my desired results using VBA, but was
wondering if it could be done with straight SQL. Thank you.

Data Source:
Item Month Qty
--------- --------- ------
12345 1 50
12345 2 65
12345 3 42
67890 1 15
67890 2 11
67890 3 26

Query Results:
Item QtyMonth1 QtyMonth2 QtyMonth3
--------- ---------------- ---------------- ----------------
12345 50 65 42
67890 15 11 26
 
B

Brendan Reynolds

Gyetko said:
I've posted an example of the Query results I would like returned from
my Data Source. Basically, I want to have one row for each item, then
have columns for the Months and show the Qty for that Item under the
given Month. I know I can get my desired results using VBA, but was
wondering if it could be done with straight SQL. Thank you.

Data Source:
Item Month Qty
--------- --------- ------
12345 1 50
12345 2 65
12345 3 42
67890 1 15
67890 2 11
67890 3 26

Query Results:
Item QtyMonth1 QtyMonth2 QtyMonth3
--------- ---------------- ---------------- ----------------
12345 50 65 42
67890 15 11 26


I think you can probably get that result using a crosstab query. I can't be
more definite than that, because for some reason I've never really made much
use of crosstab queries. But I think it's probably worth a go ... try using
the crosstab query wizard and see if it can get you what you need?
 
G

Gyetko

Sorry for the dups, I was posting using Google Groups and was getting
a message with each post. I was't able to view them after posting, so
I tried a duplicate and then a different group. Should've tried
viewing with a reader first.

Thanks for the response, crosstab does work.
 

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

Top