Where clauses that have ''['' character in value.

  • I am building up some dynamic t-sql to produce a recordset where one of the parameters sets the where clause.

    The issue is that that data contains '[' and ']' brackets

    so if the user sets the parameter for the report that includes these brackets no results are returned even though there are values.

     

  • I'm guessing you're using the LIKE clause and need to use ESCAPE...

    DECLARE @t TABLE (v VARCHAR(100))

    INSERT INTO @t

          SELECT 'abc'

    UNION SELECT 'a[c'

    SELECT * FROM @t WHERE v LIKE '%[%' --0 rows

    SELECT * FROM @t WHERE v LIKE '%\[%' ESCAPE '\' --1 row

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

Viewing 2 posts - 1 through 1 (of 1 total)

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