2

Possible Duplicate:
Is there a combination of “LIKE” and “IN” in SQL?

The first where clause below runs fine for me but it does not pick up contacts that might have 45211-1234 or 45213-4321

SELECT * FROM contacts
WHERE zipcode IN ('45211','45213')

I thought I could change the where clause to the below to fix, but it fails.

SELECT * FROM contacts
WHERE zipcode IN ('45211%','45213%')

How might I change this so it brings back anything that has proper zip + dash + any zip4? For example, 45211-1234 or 45213-4321.

Note I have whole bunch of zipcodes to enter, not just these two.

4

1 回答 1

3

How about this:

SELECT * FROM contacts
WHERE Left(zipcode,5) IN ('45211','45213')
于 2012-08-30T18:02:27.530 回答