Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favourite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved in your SSC briefcase from the favorites tab.
Download now (direct download link)

Script to find a particular string in procs/func.

By Renu Mehta,

Requirement:
I added a parameter to an existing user defined function. This user-defined function was
used in many procedures across system. Whenever a parameter is added to a user defined function, then we will have to change the calling of the function and pass the value for the new parameter added. Even though the parameter is set default value as NULL. An explicit value will have to be passed to the new parameter. The same is true when you delete a parameter from the user-defined function. If the necessary changes are not done in calling of the function then it leads to an error.
Now since I added a parameter to the existing user-defined function, I wanted to find out the names of the stored procedures / functions wherever the modified function is called. So that I can pass an additional value to the new parameter added. Hence the procedure is created.
Solution: The UP_FindAWordUsedInSPOrFun is created which takes a single parameter @FindStr. It generates a list of procedures and functions wherever the matching string is found in any of the procedures or functions.
Eg.:
A function is initially created as
Create function UF_Function1 (Parameter1 Integer) ……
A procedure is created as
Create PROC UP_Proc1(…)
As
Begin
Select * from DBO.UF_Function1(2)
end

A function is CHANGED with an additional parameter as
Create function UF_Function1 (Parameter1 Integer, Paramter2 Integer) ……
Assuming you do not know the name of the procedure where you have used the function,
Executing a UP_FindAWordUsedInSPOrFun :
EXEC UP_FindAWordUsedInSPOrFun 'UF_Function1’
The output of the procedure would be as
Name ObjectType
UP_Proc1 PROCEDURE

One can also use the procedure to find any particular string that is used in any stored procedure or function.

Total article views: 82 | Views in the last 30 days: 1
 
Related Articles
FORUM

stored procedure using user defined table type for parameters

stored procedure using user defined table type for parameters

FORUM

Stored procedure in User defined function?

Can I call Stored procedure in User defined function?

FORUM

Backup stored procedures,views,user defined functions from a db

Backup or dump stored procedures,views,user defined functions from a db

FORUM

user defined functions & columns

user defined functions & columns

FORUM

create function

create function

Tags
miscellaneous    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones