×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Query which shows results?

Query which shows results?

Query which shows results?

(OP)
Hi,

I am wondering if there is anyway to do this with an access query:

I have table1 with two fields and data:

Temp: Count:
15 2
20 3

I would like a query that generates the following results:

Results:
15
15
20
20
20

I would appreciate any direction!

RE: Query which shows results?

Code not tested...

CODE

Dim sSQL As String
Dim i As Integer

With rst
    .Open "Select * From table1"
    Do While Not .EOF
        For i = 1 To !Count.Value
            If Len(sSQL) = 0 Then
                sSQL = "Select " & !Temp.Value & " As Results From table1 " & vbNewLine
            Else
                sSQL = sSQL & " UNION ALL " & vbNewLine
                sSQL = sSQL & "Select " & !Temp.Value & " From table1 " & vbNewLine
            End IF
        Next i
        .MoveNext
    Loop
    .Close
End With

Debug.Print sSQL 

The SQL you should be getting:

Select 15 As Results From table1
UNION ALL
Select 15 From table1
UNION ALL
Select 20 From table1
UNION ALL
Select 20 From table1
UNION ALL
Select 20 From table1

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: Query which shows results?

I typically have a table of numbers to assist with tasks like this:

tblNums
Num
1
2
3
4
...

Use this table of numbers with your table in a query like:

CODE --> SQL

SELECT Temp
FROM table1, tblNums
WHERE Count>=[Num]
ORDER BY Temp; 

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close