#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Where Operator in query not working properly


    Hi, I'm using MSSQL Express 2012 an I have a column, Item_no, which is varchar. If I do a query using the "=" operatior, the result is ok but, if I use ">=" as the operator, the result starts at the begining of the table.

    Any ideas or suggestions?

    Thanks
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    If the value is numeric then the data type shouldn't be varchar; if the value is a string, then a >= comparison doesn't make a lot of sense. If you were to cast the value to a numeric data type the comparison would work, but this would be pretty inefficient.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0
    The field is, in fact, string. What would be the proper operator to use to bring all the data that starts with a partial value be?
  6. #4
  7. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    I'm not sure specifically for MSSQL, but there should be an operator that allows you to use wildcards in the comparison value which could be used to retrieve all of the rows that start with a particular value. In MySQL this is the LIKE operator, it might be the same in MSSQL.

    Alternatively, you could use the substring function to extract the starting part of the string and do an equal comparison against the value you're looking for.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  8. #5
  9. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,280
    Rep Power
    4279
    Originally Posted by juan5519
    What would be the proper operator to use to bring all the data that starts with a partial value be?
    Code:
    WHERE daColumn LIKE 'partial%'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo