Jump to content

selecting with LIKE and %'s


.josh

Recommended Posts

I have a form where I have 3 optional fields to fill out that builds a query string, and the end result could look like any one of the following, depending on whether any/all fields were filled out:

 

Returns everything....

a) .. like '%%' // everything

b) .. like '$x%%' // starting with $x

c) .. like '$x%$y%' // starting with $x, containing $y

d) .. like '$x%$y%$z' // starting with $x, containing $y, ending with $z

e) .. like '%$y%$z' // containing $y, ending with $z

f) .. like '%%$z' // ending with $z

g) .. like '%$y%' // containing $y

h) .. like '$x%$z' // starting with $x, ending with $z

 

Now the results seem to always come back the way I expect them to.  But I'm just curious about patterns a,b and f.  They seem to work...but why? I thought I would have to use extra conditions to make the string only

 

a) not include a like clause at all (so as to return everything)

b) show .. like '$x%'

f) show .. like '%z'

 

but apparently having double %'s seems to work. So...why? The manual says

 

Character Description

% Matches any number of characters, even zero characters

 

So I'm interpreting that as 0 + 0 still equals 0 in the end, no harm no foul.  Is my interpretation correct?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.