Help with a simple LIKE Query

  • I exported data out of a cobol data file and imported into SQL, I have a few hundred records where it appended some ascii junk to the end. SQL manager is showing it as a "left arrow[m left arrow [h left arrow["

    When I do a LIKE '%[%' I get no results.

    Is the [ a special character in SQL or is there a different way I can query all records that have the [ in them?

    Here is a cut and paste from SQL manager. "3C3Z*8620*BC[" junk past the*BC should not exist.

  • I cut and pasted the first box and got this to work.

    Declare @Table Table (tst nvarchar(100))

    Insert into @Table Values ('"3C3Z*8620*BC[m[H[" ')

    Select * from @Table

    Where tst like '%%'

  • This is a special character.

    There are 2 workarounds in BOL:

    http://msdn.microsoft.com/en-us/library/ms179859.aspx

    Read in this page under these subtitles:

    Using Wildcard Characters As Literals

    Pattern Matching with the ESCAPE Clause

    Let us know if it helped.

    Regards,Yelena Varsha

  • Yelena Varshal (5/22/2009)


    This is a special character.

    There are 2 workarounds in BOL:

    http://msdn.microsoft.com/en-us/library/ms179859.aspx

    Read in this page under these subtitles:

    Using Wildcard Characters As Literals

    Pattern Matching with the ESCAPE Clause

    Let us know if it helped.

    That's true. When I first looked at the post I was thinking that the bracket was a weird unicode character that would never equal the literal anyway. But it is treating it the same so the following code works as well.

    Declare @Table Table (tst nvarchar(100))

    Insert into @Table Values ('"3C3Z*8620*BC[m[H[" ')

    Select * from @Table

    Where tst like '%[[]%'

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

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