Help with sql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • colinod
    Contributor
    • Nov 2007
    • 347

    Help with sql

    I have the following sql that get information from my database fine

    Code:
    DatabaseDetails="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("../../private/yaketynew.mdb") & ";"
    yaketyConnection.Open DatabaseDetails
    yaketyQuery="SELECT * FROM celebs INNER JOIN mp3 ON celebs.idnumber = mp3.celebid where idnumber =" &actorid& " order by mp3.orderno"
    Set yaketyRecordset=yaketyConnection.execute(yaketyQuery)
    i have added another field in the database to give the mp3 an accent type and called the field voicetypea,voic etypeb ect upto voicetyped these are in the mp3 table, i have tried to change my sql to get this information as follows

    Code:
    DatabaseDetails="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("../../private/yaketynew.mdb") & ";"
    yaketyConnection.Open DatabaseDetails
    yaketyQuery="SELECT * FROM celebs INNER JOIN mp3 ON celebs.idnumber = mp3.celebid where idnumber =" &actorid& " and voicetypea = " &voiceid& " order by mp3.orderno"
    Set yaketyRecordset=yaketyConnection.execute(yaketyQuery)
    and get the following error

    Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

    [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'idnumber =1 and mp3voicetypea = All'.

    /pages/girls2.asp, line 10

    line 10 is
    Code:
    Set yaketyRecordset=yaketyConnection.execute(yaketyQuery)
    any help would be appreciated
  • colinod
    Contributor
    • Nov 2007
    • 347

    #2
    Played about with the sql statement and sorted it my sql statement now reads

    Code:
    "SELECT * FROM celebs INNER JOIN mp3 ON celebs.idnumber = mp3.celebid where celebs.idnumber =" &actorid& " and mp3.voicetypea = '" &voiceid& "' order by mp3.orderno"
    all to do with inverted commas round the right bits

    all sorted

    Comment

    • jhardman
      Recognized Expert Specialist
      • Jan 2007
      • 3405

      #3
      Right, please note that we have a SQL forum, and since the question barely concerns ASP, I would have suggested you post in the SQL forum. but this is pretty standard, SQL uses inverted commas to show that you are talking about a string: voicetype = 'all'. 'Voicetype = all' looks like you have another field named 'all' and you only want to show records that have the same value in 'voicetype' and 'all'.

      Jared

      Comment

      • CroCrew
        Recognized Expert Contributor
        • Jan 2008
        • 564

        #4
        Hello colinod,

        I would change it to:

        Code:
        yaketyQuery = "SELECT a.* FROM celebs a "
        yaketyQuery &= "INNER JOIN mp3 b ON (a.idnumber = b.celebid) "
        yaketyQuery &= "WHERE ((a.idnumber = '" & actorid & "') AND (b.voicetypea = '" &voiceid& "')) "
        yaketyQuery &= "ORDER BY b.orderno"
        Happy Coding,
        CroCrew~

        Comment

        • jhardman
          Recognized Expert Specialist
          • Jan 2007
          • 3405

          #5
          showoff !

          Comment

          Working...