Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    New Coder
    Join Date
    Oct 2002
    Location
    Noth Idaho
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with WHERE Clause

    Hi all, I have a rather strange problem with the WHERE clause of my SQL statement.
    This is what I have right now:

    sqlstmt = "SELECT * FROM TblItems WHERE MedTyp='Book'"

    For some reason it returns ALL the records in that table.

    TblItems of course is the name of the table and MedTyp is the name of the field.
    For the record, I DO have records matching the query

    (Unfourtantly) Right now I am using an Access DB. I created a query within the DB that worked just fine. I tried using that SQL statement insted of what I have now but it did the same thing.

    I response.writed the SQL statement to my page and it seemed to look fine.

    After all this it still returns ALL the records!

    Any one know what I am doing wrong?
    I have attached a copy of my page.
    Thanks a lot, Jacob
    How do you know the universe is 20,000,000,000, years old Grandpa? Were you there?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your attachment went awol.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #3
    New Coder
    Join Date
    Oct 2002
    Location
    Noth Idaho
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Woops sorry about that- my sattalit got too much rain on it just as I sent it!
    Here you are
    Attached Files Attached Files
    How do you know the universe is 20,000,000,000, years old Grandpa? Were you there?

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    try

    sqlstmt = "SELECT * FROM TblItems WHERE MedTyp like 'Book'"
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #5
    New Coder
    Join Date
    Oct 2002
    Location
    Noth Idaho
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm- that was a good idea but unfournatly it does the same thing.
    All the records are still returned.
    How do you know the universe is 20,000,000,000, years old Grandpa? Were you there?

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Are you really sure some records have MedTyp other than 'Book'?

  • #7
    New Coder
    Join Date
    Oct 2002
    Location
    Noth Idaho
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <VERY POSITIVE AWNSER> I AM SURE </VERY PSITIVE AWNSER>


    I have attached a copy of my DB if any one wanted to see it. (it's pretty small)
    Attached Files Attached Files
    How do you know the universe is 20,000,000,000, years old Grandpa? Were you there?

  • #8
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    I ran the query and I only get the records with book in it.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #9
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts
    SELECT TblItems.*, TblItems.MedTyp
    FROM TblItems
    WHERE (((TblItems.MedTyp)="book"));


    I get only the book


    SELECT TblItems.*, TblItems.MedTyp
    FROM TblItems
    WHERE (((TblItems.MedTyp) Like "book"));


    I get only the books

    I get only the books ... I get only the books ... I get only the books ... I get only the books ... I get only the books ... I get only the books ... I get only the books ... I get only the books ... I get only the books ... I get only the books ... I get only the books ... I get only the books ... I get only the books ... I get only the books

    :-))

  • #10
    New Coder
    Join Date
    Oct 2002
    Location
    Noth Idaho
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Very interesting! Could this be a problem with my PWS?
    How do you know the universe is 20,000,000,000, years old Grandpa? Were you there?

  • #11
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I cannot omagine rgat you don't get the same... then really I have no idea


    have you tried to run this command directly into your database ?

    or try it as a storedProcedure


    SELECT TblItems.*, TblItems.MedTyp
    FROM TblItems
    WHERE (((TblItems.MedTyp)=[@item]));

  • #12
    New Coder
    Join Date
    Oct 2002
    Location
    Noth Idaho
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, I ran a query on my DB in access and it worked fine. I ran a sub procedure (I think that the same thing ) and it returned ALL the records.

    This seems strange. I tried to put it on some shard server space to test it there but I havent been able to get it to read the DB path yet

    I will keep trying that and also try to make some other querys for different DB. I am not very experenced with this so it may take me some time!
    How do you know the universe is 20,000,000,000, years old Grandpa? Were you there?

  • #13
    New Coder
    Join Date
    Oct 2002
    Location
    Noth Idaho
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well I ran a copy on my Shared Server and it did the same thing... Looks like I have problem somwhere

    I apreiciate you guys sticking with me.
    I attached a copy of my included file that ha all my stored procedures on it for any one to take a look at if the want.

    Thanks,
    Attached Files Attached Files
    Last edited by Jacob-Bushnell; 11-21-2003 at 11:39 PM.
    How do you know the universe is 20,000,000,000, years old Grandpa? Were you there?

  • #14
    Regular Coder
    Join Date
    Oct 2003
    Location
    London, UK
    Posts
    411
    Thanks
    0
    Thanked 1 Time in 1 Post
    To be honest, this is such a *basic* query that the problem must either be something very freaky, or something rather obvious.

    Given that you are using Access, I suspect that replacing the single quotes with double quotes (the correct syntax for a string in JET SQL) will solve it:
    Code:
    sqlstmt = "SELECT * FROM TblItems WHERE MedTyp=""Book"""
    I'd like to add that using SELECT * is considered *very* bad practice, even if you DO want all the fields returned. I once wrote a rather lengthy explanation on why not, but can't find the post, so read this instead (which is probably better anyway):
    http://www.adopenstatic.com/faq/selectstarisbad.asp
    Marcus Tucker / www / blog
    Web Analyst Programmer / Voted SPF "ASP Guru"

  • #15
    New Coder
    Join Date
    Oct 2002
    Location
    Noth Idaho
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I agree with you about it being eithier freaky or basic and judging by my VERY limited experence it is probably the latter!

    I tried changing the single quotes to doubles but got an error message saying:
    Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
    [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

    I am rather young and inexperienced as you can probably tell by my programing! I have posted a new copy of my code with the other lines I have tried commented out.

    I hope somone can spot this "invisble" error somwhere!
    Thanks, Jake
    How do you know the universe is 20,000,000,000, years old Grandpa? Were you there?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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