idksoiputthis
idksoiputthis

Reputation: 121

Why does the use of '_' wildcard in SQL not display any results?

For some reason, this executes and shows the Phone column, but it does not display and rows of data. I checked the numbers on the phone search with the data in the column, and I did not make any typos. Am I using the wild card in an incorrect format?

SELECT Phone
FROM EMPLOYEE
WHERE Phone LIKE '360-287-_'

Upvotes: 0

Views: 56

Answers (3)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520958

Underscore matches any single character, so the pattern 360-287-_ would match, for example, the number 360-287-1, but not 360-287-12, or any similar longer number.

Perhaps you intended to use the pattern 360-287-%, which would match any number starting with 360-287-.

Upvotes: 3

DYZ
DYZ

Reputation: 57033

You are probably looking for four more digits, not one:

SELECT Phone
FROM EMPLOYEE
WHERE Phone LIKE '360-287-____'

Upvotes: 2

Gordon Linoff
Gordon Linoff

Reputation: 1269553

I imagine that you want %, not _. The latter only matches a single character:

SELECT Phone
FROM EMPLOYEE
WHERE Phone LIKE '360-287-%'

Upvotes: 1

Related Questions