469,887 Members | 1,945 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,887 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
1 142887
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.