SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    WHERE command OK with number but bad with VARCHAR ?

    HI I have a table to store weblink like this :

    linknumber(int), linkadress(VARCHAR),
    linkname(VARCHAR), linkcategory(VARCHAR)

    Example of data in my table :

    1, http://hytekk.com, my first site,test


    When I do a search with WHERE apply to a number it's OK, it show my row.

    SELECT * FROM mydb WHERE linknumber="1" ( OK STRING )

    But when a do a WHERE to linkcategory it did'nt give my any row.

    SELECT * FROM mydb WHERE linkcategory="test" ( BAD STRING )


    Look like a mismatch of data type ?? I don't know what's wrong

    Can someone help ?



    Thank you !

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Ukraine, Khmelnitsky
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    May be
    linkcategory LIKE "%test%"
    ?
    Sergey Bres aka tserbis, Ukraine

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,250
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    use the single quote for strings
    Code:
    SELECT * FROM mydb WHERE linkcategory='test'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I try the command : linkcategory LIKE "%test%"
    and that work OK.

    But when I need to be more specific with linkcategory = 'test' it didn't show me anything.

    I have many row with linkcategory = test, it's that my problem ?

    Thank you so much for your help !!!


  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,250
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    please display a few sample rows which contain the data values you are trying to find
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here a sample table

    linknumber, linkadress, linkname, linkcategory

    1, http://hytekk.com, my first site, test
    2, http://intrumental.net, my friend site,test
    3, http://cj.com, my affiliate site, test
    4, http://tenbyten.org, News site, news

    It look like this.

    thank you !

  7. #7
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You may have some extra space(s) in the linkcategory field, try cleaning it up with this...
    Code:
    UPDATE 
    	mydb
    SET 
    	linkcategory = trim(linkcategory)
    Lats...

  8. #8
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had trim my field but still no result ...
    I am still unable to compare direct string statement
    Indirect string work ...
    When I compare direct number it's work fine .

    Maybe it is the table I create ? ( See my first post )
    I set linknumber to PRIMARY KEY and that's all ...

    We will triumph !

  9. #9
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,250
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    do you have phpmyadmin or a similar front end program?

    please dump the table structure and a few rows of data so that i may test this for myself
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •