Rabcor
Rabcor

Reputation: 249

SQL How to target a specific part of a string

I have a varchar(11) table and all its entries will look something like this.

Table
123456-7890
101112-1314

I need to find everything that has

??12??-????

(? Being any character) How would I do this?

Edit: Thanks bill!!

SELECT * FROM myTable WHERE myfield LIKE '__12%'

Is what i was looking for :)

Upvotes: 2

Views: 229

Answers (2)

Bill
Bill

Reputation: 3672

Assuming you're using ANSI SQL, what you're looking for is '_':

SELECT * FROM myTable WHERE myField LIKE '__12__-____'

For most Microsoft products, the question mark, as you used it is, is correct.

Upvotes: 1

Martin Smith
Martin Smith

Reputation: 453648

WHERE YourColumn LIKE '__12__-____'

The _ means "match any single character"

Upvotes: 4

Related Questions