Results 1 to 3 of 3

Thread: Experts..need help!!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Charlotte
    Posts
    127

    Cool

    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?

  2. #2
    Member
    Join Date
    Feb 2001
    Location
    NewYork
    Posts
    53
    Send the SQL statement to the debug window and see what it looks like. Myabe the SQL statement needs some improvement.

  3. #3
    Fanatic Member Jerry Grant's Avatar
    Join Date
    Jul 2000
    Location
    Dorset, UK
    Posts
    810
    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.
    Jerry Grant................tnarG yrreJ
    Website: <JG-Design></.net>
    Email: [email protected]
    Working towards a bug free world......
    (Not a Microsoft employee)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width