3

Possible Duplicate:
How to Use 'Like' with a parameter

How do you do this?

 SELECT * FROM TABLE WHERE COL LIKE % @PARAM %

I would like to avoid passing %value% in a statement.

Community
  • 1
  • 1
Control Freak
  • 12,965
  • 30
  • 94
  • 145
  • What language are you using? Elaborate? – Isaac Fife Dec 19 '11 at 20:30
  • Frankly you should avoid doing this type of query altogether. Ther is no way a query like this can use an index. Why do you need a wildcard for the first character? Is youe data model bad , storing things ina comma delimited string perhaps? Or is this something that woudl be better served with using a full-text index? Wanting to do this is a huge database smell. – HLGEM Dec 19 '11 at 22:02

2 Answers2

7
SELECT * FROM TABLE WHERE COL LIKE '%' + @PARAM + '%'
hspain
  • 17,528
  • 5
  • 19
  • 31
1

Here you go.........

LIKE '%' + @PARAM + '%'
Valamas
  • 24,169
  • 25
  • 107
  • 177