Allow,users,search,thru,objects,value,they,lo
Quick Search for:  in language:    
Allow,users,search,thru,objects,value,they,lo
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
SQL Stats

 Code: 25,719 lines
 Jobs: 420 postings

 
Sponsored by:

 

You are in:

 
Login



Latest Code Ticker for SQL
Validate Email
By Lewis Moten on 6/22


IsAlphaNumeric
By Lewis Moten on 6/22


ValidFilename
By Lewis Moten on 6/22


Job to script all Jobs
By Srdjan Josipovic on 6/19


Enumerate SQL Servers using SQLDMO and T-SQL
By Srdjan Josipovic on 6/19


Count Colums
By Usman Farhat on 6/19


Easy travel SQL logins
By Zoltan Tamas, Toth on 6/17


Build a sequence via derived tables
By Michael S. Trachtenberg on 6/15


Click here to see a screenshot of this code!Creating Grids
By Lewis Moten on 6/15

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

Find a string in Procedures, Triggers, Constraints, Defaults, Functions, and Views

Print
Email
 
VB icon
Submitted on: 2/20/2002 8:05:10 AM
By: James Travis  
Level: Intermediate
User Rating: By 5 Users
Compatibility:SQL Server 7.0, Other

Users have accessed this code 2705 times.
 

(About the author)
 
     Allow users to search thru objects for a value they are looking. This may be items that touch a specific table/view or items that need to be replaced.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

--**************************************
--     
-- Name: Find a string in Procedures, Tr
--     iggers, Constraints, Defaults, Functions
--     ,and Views
-- Description:Allow users to search thr
--     u objects for a value they are looking. 
--     This may be items that touch a specific 
--     table/view or items that need to be repl
--     aced.
-- By: James Travis
--
-- Inputs:@find = the value(s) to search
--      for
@type = the type OF objects TO search
--
-- Returns:The names of objects that con
--     taint th search criteria.
--
-- Assumes:First off this will not work 
--     for any items that have the WITH ENCRYPT
--     ION remark in them. With this is can pos
--     e a string such as 'INSERT' against all 
--     the 'P'rocedures to get a return of whic
--     h Procedures have an INSERT statment in 
--     them or you can do word strings such as 
--     'FROM TABLE1 WHERE COL1 =' or string lis
--     t searches such as 'INSERT%TABLE1%COL1 =
--     '. You can use any valid like strings yo
--     u wish, but you don't need leading and e
--     nding wildcards as general most items st
--     art with a specific item such as CREATE 
--     which will be contained in the majority 
--     of code items. This is compatible with S
--     QL 7/2000.
--
--This code is copyrighted and has-- limited warranties.Please see http://
--     www.Planet-Source-Code.com/xq/ASP/txtCod
--     eId.414/lngWId.5/qx/vb/scripts/ShowCode.
--     htm--for details.--**************************************
--     

CREATE PROCEDURE sp_FindStringInCode
/* Input variables, DEFAULT NULL FOR custom error output. */
@find VARCHAR(50) = NULL,
@type VARCHAR(2) = NULL
AS
/* CHECK FOR NULL or invalid input AND show custom error. */
IF @find IS NULL AND @type IS NULL
    BEGIN
    	RAISERROR ('This PROCEDURE has two required parameters @find AND @type',16,-1)
    	RETURN
END

ELSE IF @find IS NULL BEGIN RAISERROR ('You must enter a valid LIKE criteria FOR @find without the leading/ending % wildcard.',16,-1) RETURN END
ELSE IF @type IS NULL OR @type NOT IN ('C','D','FN','P','TR','V') BEGIN RAISERROR('No value was entered FOR @type. Valid VALUES FOR @type are C = CHECK CONSTRAINT D = DEFAULT FN = Function P = PROCEDURE TR = TRIGGER V = View',16,-1) RETURN END
/* SET wildcards ON END OF find value. */ SET @find = '%' + @find + '%' /* Output object names which contain find value. */ SELECT DISTINCT OBJECT_NAME([id]) FROM syscomments WHERE [id] IN (SELECT [id] FROM sysobjects WHERE xtype = @type AND status >= 0) AND [text] LIKE @find


Other 19 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
2/21/2002 4:28:19 AM:Peter Wilkinson
Very nice procedure James. I have been 
looking for something like this for a 
while. However, I found that some 
stored procedures appeared more than 
once in the final select, so have 
modified it to a 'DISTINCT' 
select.
Keep putting up your 
procedures, they are always useful.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/21/2002 6:05:45 AM:James Travis
Thanks, I went ahead and made the 
change. Unfortunately in my environment 
this is not happening so I had no 
examples of this when testing.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/21/2002 10:02:45 AM:Rasputin
Hey James,
Excellent!  5*'s from 
me.
...wish more PSC submissions 
were like yours - high 
quality!
Thanks for sharing your 
high caliber work! 
- Ras
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | SQL Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.