|
-
Feb 23rd, 2001, 10:53 AM
#1
Thread Starter
Lively Member
I'm trying to use a select top 10 or 25 or 50 T-SQL in VB...This code I wrote doesn't seem to do the job..can any experts help ..
sSQL = "Select Top " & Parameters("sReportValue") & ""
sSQL = sSQL & "DocumentName, HitCount "
sSQL = sSQL & "from RollupDocument, RollupLookupDocument "
sSQL = sSQL & "Where RollupType=" & iRollupType
sSQL = sSQL & " and RollupYear=" & iRollupYear
sSQL = sSQL & " and RollupValue=" & iRollupValue
sSQL = sSQL & " Order by Hitcount Desc"
lRet = objDB.FillRecordsetWeb(rsDetailedHits, sSQL)
can I use an else if statemnet within sSQL...where it says select top ..either top 10 or 25 or 50?
-
Feb 23rd, 2001, 12:02 PM
#2
Member
Send the SQL statement to the debug window and see what it looks like. Myabe the SQL statement needs some improvement.
-
Feb 23rd, 2001, 12:06 PM
#3
Fanatic Member
Your SQL statement was incorrect:
I have rewritten it assuming all the field referenced are in a single table:
Code:
sSQL = "SELECT TOP " & intRowReqd & " DocumentName, HitCount " & _
"FROM RollupDocument " & _
"WHERE RollupType = " & iRollupType & " " & _
"AND RollupYear = " & iRollupYear & " " & _
"AND RollupValue = " & iRollupValue & " " & _
"ORDER BY Hitcount Desc"
The variable intRowReqd will be your selected 10, 25 or 50.
Your statement had two tables 'RollupDocument' and 'RollupLookupDocument' specified withot a JOIN. If the selected fields are from both then you should explicitly use the table.field in the SELECT and WHERE clause, using table1.joinfield = table2.joinfield' to JOIN them.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|