-1

I need to find a list of all items starting with an underscore: _

The obvious doesn't work:

select * from role where Name like '_%'

This still returns all items.

The following also returns all items.

select * from role where Name like '\_%'
select * from role where Name like '__%'

anyone knows how to escape a underscore? or how else I can achieve this StartWithUnderscore functionality?

z0mbi3
  • 336
  • 4
  • 14

2 Answers2

1

I found the answer:

select * from role where Name like '[_]%';

z0mbi3
  • 336
  • 4
  • 14
0

You can escape with any character you want eg

select * from role where Name like '!_%' ESCAPE'!'

You can read more on this page: LIKE (Transact-SQL)

TT.
  • 15,774
  • 6
  • 47
  • 88