问题
This seems pretty straightforward, but for some reason I'm not finding anything about how to do it. I'm using SQL Server Management Studio 2012, and I have a set of results returned from a SELECT query, say, select a,b from x
. How can I search in column b
for a substring? In Access I would click on the column and type Ctrl+F, but in SSMS that seems to only be used for searching the SQL itself, not the results. How can I search in my results? I know I can modify my query to only return that result, e.g.:
select a,b from x where b like '*hello*'
but I want to get all the rows returned, not just that one.
UPDATE: The responses I'm getting are about how to build a query that selects only the rows I'm looking for, which, as I specified above, is not what I'm looking for. I want all rows returned, and I want to look around in the search results in the SSMS interface to find the desired values. The reason is that I want to see these values in the context of other rows that don't have them.
回答1:
In SQL Server Management Studio, you can output your query results to text (CTRL + T), re-run your query, click in the results pane, and CTRL + F to find strings from an unfiltered query. To revert query results to grid, hit CTRL + D.
回答2:
There is no native SSMS functionality to search through results grid.
That is why I have added this function into my add-in (SSMSBoost): it allows to search through results grid using wildcards. There are some other add-ins allowing to do it as well.
回答3:
select a, substring(b, 2, 3) as b from x
回答4:
Use:
select a,b from x where b like '%hello%'
Or:
select a,b from x where charindex('hello',b)>0
CHARINDEX is far faster than LIKE.
来源:https://stackoverflow.com/questions/22543760/how-to-search-for-a-string-substring-in-ssms-results