Click here to Skip to main content
15,883,901 members
Articles / Programming Languages / SQL
Tip/Trick

Get given string instance from SQL database

Rate me:
Please Sign up or sign in to vote.
4.20/5 (2 votes)
19 Jan 2011CPOL 13.9K   1   6
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)


Written By
Software Developer (Senior) Tata Teleservices ISP
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralThank you for the comment and vote Gandalf! Pin
That's Aragon27-May-11 3:36
That's Aragon27-May-11 3:36 
GeneralReason for my vote of 5 Thanks for Sharing, It helped me. Pin
Gandalf_TheWhite27-Jan-11 1:58
professionalGandalf_TheWhite27-Jan-11 1:58 
GeneralThanks for comment Lyra. Pin
That's Aragon19-Jan-11 0:26
That's Aragon19-Jan-11 0:26 
GeneralGood tip Aragon, Thanks. Pin
Lyra Belaqua19-Jan-11 0:05
Lyra Belaqua19-Jan-11 0:05 
GeneralThank you Pranay. :) Pin
That's Aragon18-Jan-11 23:43
That's Aragon18-Jan-11 23:43 
GeneralReason for my vote of 4 thanks for sharing... Pin
Pranay Rana18-Jan-11 23:26
professionalPranay Rana18-Jan-11 23:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.