Search number in a varchar field using LIKE statement

Good morning,i have a little problem with a query to finding a record within a varchar field.

My table is composed of two field: codice and giacenza where codice is a varchar field type.

I need to find all the record start with a number.

The query i have tried is:

SELECT codice,giacenza FROM prodotti WHERE codice like 'AC%' OR '160%'

and this:

SELECT codice,giacenza FROM prodotti WHERE codice like 'AC%' OR '160_'

but returned me ALL the record and not only the row start with AC and 160. If i delete the OR '160%' or the OR '160_' the query return me the right record: only the row start with AC.

I have read after a research with google,that you can not use the wildcard with a number. It's that correct?

There's a method to resolve my problem with this query?

Thanks in advance.


your query is

SELECT codice,giacenza FROM prodotti WHERE codice like 'AC%' OR '160%'

when processed the codition will be treated as

        ( codice like 'AC%') // codition 1  which will True or false 
      OR ('160%')   // condition 2 will always true 
   one codition True in OR means expression true for all

which means ('160%') will always result true for all rows

query should be like this

SELECT codice,giacenza FROM prodotti WHERE codice like 'AC%' OR  codice like  '160%'

here is the solution :---

SELECT codice,
FROM prodotti
WHERE codice LIKE 'AC%'
  OR codice LIKE '160%'

let me know, if you accept this answer.

Need Your Help

Fluent NHibernate Many-to-Many

c# nhibernate fluent-nhibernate fluent

I am using Fluent NHibernate and having some issues getting a many to many relationship setup with one of my classes. It's probably a stupid mistake but I've been stuck for a little bit trying to g...

c++ not writing to console unless a newline was encountered

c++ constructor newline stdout

I was recently writing a simple c++ program involving sockets. It had been a while since I worked with c++, so i was doing some simple sanity checking to make sure my classes were properly construc...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.