Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / SQL

Get given string instance from SQL database

4.20/5 (2 votes)
19 Jan 2011CPOL 15.2K  
This is a SQL query to search particular string instance from SQL database.
Once I had to get given string instance from SQL database within the instances of my database objects, like from table, stored procedure, etc.

My role was to replace status text Active, Inactive, Pending and NA with something else provided by the client. I didn't know in how many stored procedures this status was used, but had information that all the item statuses were managed via stored procedures. For example, consider the member status. They were using case statements to check the status.
CASE WHEN Status = 0 THEN 'Active' WHEN Status = 1 THEN 'InActive' WHEN Status = 2 THEN 'Pending' ELSE 'NA' END AS MemberStatus


So, I used the following query to find the list of database objects in which to search for the particular term.
SELECT routine_name, routine_definition  FROM information_schema.routines where routine_definition like '%Active%'


One can filter it based on the requirement, like append AND condition, with routine_type = 'procedure' or as per requirement.

Hope it helps.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)