0

Can anyone help me out with this-

There is a column in the database as "TEXT". This column hold some string value. I want to search any row that is having '%' in this column .

For eg how will i search for a row having value 'Vivek%123' in the column TEXT

2 Answers2

1

You must escape the % character

WHERE COL1 LIKE 'Vivek@%123' ESCAPE '@' ;
Iswanto San
  • 18,263
  • 13
  • 58
  • 79
1

In sql there is something known as an escape character, basically if you use this character it will be ignored and the character right behind it will be used as a literal instead of a wildcard in the case of %

WHERE Text LIKE '%!%%'
ESCAPE '!' 

The above sql statement will allow you to search for any string containing a percentage character '%' so it could find anything in the format of

string%string

Jeremy C.
  • 2,405
  • 1
  • 12
  • 28
  • and it's alerady been answered because I'm too slow :p – Jeremy C. May 04 '15 at 09:51
  • Can we do the same thing using [%], if yes then how? – Vivek Rana May 04 '15 at 09:56
  • In transact sql the [ ] around the % acts the same as the escape character so the sql would become "LIKE '%[%]%' as for normal sql I don't really know, let me look that up – Jeremy C. May 04 '15 at 13:57
  • square brackets are normally used to get a single character from a list of characters eg. if you say like 'a[bcde]f' you would find everything from 'abf' to 'aef' so I don't really think it is meant to be used this way – Jeremy C. May 04 '15 at 14:08