SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Sep 2001
    Location
    USA
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL - syntax error

    can someone tell me what part is wrong in this??
    i didn't create it...but it gives me an error.


    rsLinks.Open("SELECT TOP 5 * FROM FORUM_Site_Links WHERE Added >= '" & lastDate & "' AND Validated = 1 ORDER BY ADDED DESC")

    Here's the error(500.100):

    Error Type:
    Microsoft OLE DB Provider for ODBC Drivers (0x80040E09)
    [TCX][MyODBC]You have an error in your SQL syntax near '5 * FROM FORUM_Site_Links WHERE Added >= '20010915172511' AND Validated = 1 ORDE' at line 1
    /morpheus/forum/include/newlinks.asp, line 28


    I'm not real keen on syntax yet
    Thanks!

  2. #2
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not sure...but....
    u got

    "TOP 5 *"


    usualy u put the collums u want to collect there.. and if u have more than one u have a comma, and if u want them all u put a "*"

  3. #3
    SitePoint Member
    Join Date
    Sep 2001
    Location
    USA
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <--- newbie

    is TOP 5 part of the SQL language, or is it suppose to be a table in this database? i don't see a TOP 5 in the database...so i'm assuming the first.

    and what does it mean "....at line 1" at the end of the error message?

    thanks...

  4. #4
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Top is a part of the language I believe, however, "top 5" is not. And the * there, as slightlywhacked said, is used if you want ALL of the values displayed from a given condition within the where clause or whatever. Remove the * and see what happens.

    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  5. #5
    SitePoint Addict lveale's Avatar
    Join Date
    Jun 2001
    Location
    Dublin
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    TOP 5 is okay. It is used to select the top five results from the query. However, I haven't used it in conjunction with '*'.

    Here is an example of how I used it and it worked.

    PHP Code:
    //if numStories >0, return 'numStories' rows
    if($numStories 0)
    {
        
    $query "SELECT TOP $numStories newsid, headline, story, extendedStory, author, authoremail, dateposted " .
    "FROM news ORDER BY dateposted DESC";



  6. #6
    SitePoint Enthusiast kcabobert's Avatar
    Join Date
    Aug 2001
    Location
    Topeka, KS
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the * is okay, if the result is then used properly. Like loop through the result echoing one col at a time. but if that will not change then there is no need to rewrite your query, if it works right.

    Good Luck
    Microsoft's Motto: Resistance is futile, you will be assimilated.

    My dog's name is Jade; she is a Miniature pinscher.
    Click here to see some of her pictures


Bookmarks

Posting Permissions

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