467,136 Members | 1,330 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,136 developers. It's quick & easy.

Equivalent of "Startswith", "Endswith", "Contains" string comparisons in t-sql?

Hi,

I would like to select records from a table where the following criteria
hold:

SELECT * from Mytable where

field x "contains" string @X

or

field x "starts with" string @X

or

field x "ends with" string @X

What would the syntax for the "LIKE" predicate be in each of these
instances?
Thanks.
Jul 20 '05 #1
  • viewed: 137088
Share:
1 Reply
I got it:

startswith: WHERE x LIKE @Value + '%'

endswith: WHERE x LIKE '%' + @Value

contains: WHERE x LIKE '%' + @Value + '%'

"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:c7*******************@news.demon.co.uk...
Hi,

I would like to select records from a table where the following criteria
hold:

SELECT * from Mytable where

field x "contains" string @X

or

field x "starts with" string @X

or

field x "ends with" string @X

What would the syntax for the "LIKE" predicate be in each of these
instances?
Thanks.

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.