472,142 Members | 1,073 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,142 software developers and data experts.

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 147731
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 Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.