SQL Server Management Studio - using multiple filters in table list?

Viewed 46961

In Management Studio, you can right click on the tables group to create a filter for the table list. Has anyone figured out a way to include multiple tables in the filter? For example, I'd like all tables with "br_*" and "tbl_*" to show up.

Anyone know how to do this?

10 Answers

No, you can't do this. When we first got Management Studio I've tried every possible combination of everything you could think of: _, %, *, ", ', &&, &, and, or, |, ||, etc...

At first it looks like it could use a CONTAINS query (e.g. "br_*" OR "tbl_*"), but it doesn't seem to. It seems to only support a value that is then passed into a LIKE clause (e.g. 'app' becomes '%app%').

I've used Toad for SQL Server (freeware version) which has very nice filtering options.

The "sql injection" method still works (v17.5), but with a twist:

zzzz' or charindex('pattern1',  name) > 0  or charindex('pattern2', name) > 0 or name like 'zzzz

(I used the 'zzzz' to bypass the '%')

It doesn´t work if '_' or '%' is used in the patterns (or anywhere on your code), because it will automatically be replaced by '[_]' or '[%]' before evaluation.

The SQL injection method still works (somewhat) as of SSMS 2017 v17.8.1, although it puts brackets around the % symbol, so it will interpret those literally.

If you're using the Name->Contains filter, Profiler shows: ... AND dtb.name LIKE N'%MyDatabase1%')

So, in the Name->Contains field: MyDatabase1') OR (dtb.name LIKE 'MyDatabase2 should do it for simple cases.

Related