Reputation: 79
I have a table in my database where I inserted all table names in my database. For example I have table name [test].[TestTable] and when I run this query
select * from Tables where Name like N'%[test].[TestTable]%'
it doesn't return any value but this query works:
select * from Tables where Name like N'%[TestTable]%'
Can someone explain me why?
Upvotes: 0
Views: 778
Reputation: 26
when u use the operator LIKE and in the condition add [], it has another meaning. LIKE "reads" it as any single character within the specified range ([a-f]) or set ([abcdef]).
try using: like N'%TestTable%'
Upvotes: 0
Reputation: 272106
You have to escape the left square bracket:
SELECT * FROM Tables WHERE Name LIKE N'%[[]test].[[]TestTable]%'
-----------------------------------------^ ^
--------------------------------------------------+
Upvotes: 1