December 28th, 2012, 01:54 PM
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?
December 28th, 2012, 02:58 PM
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.
December 28th, 2012, 03:41 PM
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?
December 28th, 2012, 06:56 PM
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.
December 28th, 2012, 07:56 PM
Originally Posted by juan5519
WHERE daColumn LIKE 'partial%'