Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting query that will have the number of records as one fields sum

Status
Not open for further replies.

inso18

Technical User
Dec 30, 2006
147
IL
Users and experts,
I have a pretty unusual select query I would like to build.

In a table I have Amount field and EventDate field. I need the number of records to be as the sum of Amount field, in the following way:

Original Table:

Amount EventDate
1 8/10/2002
1 9/10/2002
3 10/10/2002
2 11/10/2002
4 12/10/2002

( 11)

Select Query:

Amount EventDate
1 8/10/2002
1 9/10/2002
1 10/10/2002
1 10/10/2002
1 10/10/2002
1 11/10/2002
1 11/10/2002
1 12/10/2002
1 12/10/2002
1 12/10/2002
1 12/10/2002

( 11)

Any ideas how this is possible to achive?
Thanks for the help.
 
create an integers table as follows --
Code:
create table integers 
(i integer not null primary key);
insert into integers (i) values
(0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
now you can generate as many rows as the Amount value, assuming no Amount value is greater than 9, using the following join
Code:
select 1 as Amount
     , EventDate
  from integers
inner
  join yourtable
 where i between 1 and Amount
:)

r937.com | rudy.ca
 
Thanks,

I'm using ms-access sql queries and can't preform the command
Code:
Select 1 as Amount, EventDate from integers
as 1 is not a field and EventDate isn't on integers table.

Any suggestions?
Thanks again.
 
if you have an access problem, you should probably post your question in the access forum

yes, 1 is not a field, it is a numeric literal

the query should work regardless, assuming EventDate is the name of the column in your table

note that you never did say what your table name was

r937.com | rudy.ca
 
I thought creating an SQL command is the same in ms-access.

the table can be called myTable.

So if I have myTable with the fields Amount and EventDate field and the table Integers with i field, what is the correct command? And is it possible at all to combine it, considering I'm using ms-access?
 
It didn't work, but some someone have combined the query that works for me. If you're intersted I can ask those who have helped me if it's ok to post it.
 
I'm sure you know what you're talking about with your code, but maybe I haven't explained correctly the situation, or you haven't understood me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top