I have placed the code for the full stored procedure on git hub here: GitHub Full Procedure Code
I will only display the changes I made in the interest of keeping this post from filling your screen with code.
/*
Created by SQLWorks blog 2012
http://SQLWorks.blogspot.com
SQLWorkers@gmail.com
*/
CREATE PROCEDURE Usp_search @search_str VARCHAR(1000)
AS
SET nocount ON
...
I added the CREATE statements in the beginning, and made a couple of tweaks to the dynamic SQL in order to prevent duplicate results, see comments in the full code for details.
The usage is different of course, now you will use EXECUTE to run your new procedure and pass in the string you are searching for as a parameter as shown below.
EXECUTE Usp_search 'Employees'
Which yields the following results showing this keyword is present in two object names:
Let's pass in a keyword present in column names:
EXECUTE Usp_search 'EmployeeID'
The results yielded are shown below:
Now you can incorporate this procedure into jobs or other processes on your database server or in your applications, or base a report on it to allow users to search for items in your databases as well.
Part 4 coming up next, creating an SSRS report around this procedure
Go back to Part 1
Go back to Part 2
No comments:
Post a Comment