Search for Underscore (_)

  • How do search a table for anything containing an underscore? Since this is a wildcard in SQL I can not find a way to search for it.

    SELECT ID FROM PART WHERE ID LIKE '%_%'

  • DECLARE @Table TABLE (RowID int IDENTITY(1,1), Col1 varchar(10))

    INSERT INTO @Table(Col1)

    SELECT 'test' UNION ALL

    SELECT 'T_est'

    SELECT *

    FROM@Table

    WHERECHARINDEX('_',Col1) > 0

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • SELECT ID FROM PART WHERE CHARINDEX('_',ID) > 0

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg
  • Perfect! Thanks.

  • bpowers (3/30/2010)


    How do search a table for anything containing an underscore? Since this is a wildcard in SQL I can not find a way to search for it.

    SELECT ID FROM PART WHERE ID LIKE '%_%'

    You can escape the wildcard by wrapping square brackets around it. The charindex solution works too.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply