...

View Full Version : Select Top (help)



JANLEE
09-03-2005, 02:12 AM
Hi friends,

Please, how I do the following statement dynamically for any value of 'choice' and for all records?

The examp;le:
SELECT TOP 2 * FROM tableyy WHERE choice = 2 GROUP BY choice, freq,key_b ORDER BY freq DESC

SELECT TOP 3 * FROM tableyy WHERE choice = 3 GROUP BY choice, freq,key_b ORDER BY freq DESC

SELECT TOP 4 * FROM tableyy WHERE choice = 4 GROUP BY choice, freq,key_b ORDER BY freq DESC


Thanks for any assistance

janLee

PremiumHost
09-03-2005, 07:36 AM
Do we have SELECT TOP ??? :confused: Correct me if i'm wrong.
What you can do is create a for loop and get the first 2 records, "manually" select :D

NancyJ
09-03-2005, 12:14 PM
Do we have SELECT TOP ??? :confused: Correct me if i'm wrong.

yes :p

not sure quite what you mean Jan, but I'm assuming the option value comes from a form so it would be something like



strSQL = "SELECT TOP "&request.form("choice")&" * FROM tableyy WHERE choice = "&request.form("choice")&" GROUP BY choice, freq,key_b ORDER BY freq DESC"

JANLEE
09-03-2005, 01:13 PM
Soorry, sorry, it is a question regarding Visual FoxPro!

JanLee

miranda
09-03-2005, 09:36 PM
Do we have SELECT TOP ??? :confused: Correct me if i'm wrong.
What you can do is create a for loop and get the first 2 records, "manually" select :D

1) Yes there is a keyword TOP for use in SQL statements to get the top records.

2) it is much faster to get the results from sql than it is to get all records and loop through them.


assuming the value is gathered through a form item named choice

Dim x : x = request.form("choice")
If IsNumeric(x) Then 'makes sure it is a number that is passed
"SELECT TOP " & x & " * FROM tableyy WHERE choice = " & x & " GROUP BY choice, freq,key_b ORDER BY freq DESC;"
End If

JANLEE
09-16-2005, 08:35 PM
Miranda,

Thank you.

JLee



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum