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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robin Tucker

    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.


  • Robin Tucker

    #2
    Re: Equivalent of "Startswit h", "Endswith& quot;, "Contains& quot; string comparisons in t-sql?

    I got it:

    startswith: WHERE x LIKE @Value + '%'

    endswith: WHERE x LIKE '%' + @Value

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

    "Robin Tucker" <idontwanttobes pammedanymore@r eallyidont.com> wrote in
    message news:c78edl$3pm $1$8300dec7@new s.demon.co.uk.. .[color=blue]
    > 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.
    >
    >[/color]


    Comment

    Working...