back to top

Searching SQL Server Views, Stored Procedures, and Functions for a Specific String

Searching SQL Server Views, Stored Procedures, and Functions for a Specific String

Whether you’re cleaning up legacy code, troubleshooting a data issue, or just trying to track down where a particular table, field, or string is used, being able to search through your database objects quickly can save a ton of time.

While this tip isn’t exclusive to Infor CRM, it’s something every Infor CRM developer will run into eventually — especially when dealing with customizations, integrations, or simply trying to understand what’s going on behind the scenes.

Here’s a handy SQL script that will search through view definitions, stored procedures, and functions to find any occurrence of a specific string.


Use Case

Let’s say you want to find where CustomerID is referenced in your database. It could be in a view used for reporting, in a stored procedure that runs during a job, or in a function used for business logic. Instead of checking each one manually, just run the following script:

SELECT 
    o.name AS ObjectName,
    s.name AS SchemaName,
    o.type_desc AS ObjectType,
    m.definition AS ObjectDefinition
FROM 
    sys.sql_modules m
JOIN 
    sys.objects o ON m.object_id = o.object_id
JOIN 
    sys.schemas s ON o.schema_id = s.schema_id
WHERE 
    m.definition COLLATE Latin1_General_CI_AS LIKE '%CustomerID%'
    AND o.type IN ('V', 'P', 'FN', 'IF', 'TF');  -- Views, Procs, Scalar, Inline & Table-valued Functions

Object Types Explained

The script filters to include the most common programmable objects:

  • 'V' = View
  • 'P' = Stored Procedure
  • 'FN' = Scalar Function
  • 'IF' = Inline Table-valued Function
  • 'TF' = Table-valued Function

You can add or remove types depending on what you’re interested in.


Why This Matters for Infor CRM

Infor CRM relies on many database objects for customizations — views used in reports or filters, procedures called by web or job services, and functions that compute logic behind the scenes. If you’re working with a heavily customized environment, knowing exactly where a field is referenced helps:

  • Track down business logic affecting a specific entity
  • Understand data dependencies when planning schema changes
  • Safely rename or deprecate old fields or tables
  • Identify performance or data flow issues

If you found this helpful, stay tuned for more SQL Server tips — especially those useful in the context of Infor CRM development or troubleshooting. Got a cool query of your own? Let me know in the comments!

Contact Customer FX for your CRM project
We let our expertise speak for itself - let us know how our all-star team can help on your CRM project
About the Author
Jason Buss
Jason Buss
Jason is a senior application developer with Customer FX.

2 COMMENTS

  1. Hi,

    I made this one to search in code source some keyword :

    POSGRESQL

    -- Usage select * from fn_search_source_code(ma_recherche)
    CREATE OR REPLACE FUNCTION fn_search_source_code(search_text text)
    RETURNS TABLE(package_name varchar, schema_name varchar, manager_name varchar, search_result text) AS $$
    BEGIN
       RETURN QUERY
    	select 
    		pack."Name"::varchar as package_name,
    		sch."Name"::varchar as schema_name, 
    		sch."ManagerName"::varchar as manager_name,
    		substring(convert_from(content."Content", 'UTF-8'), position(search_text in convert_from(content."Content", 'UTF-8')), 200)::text as search_result
    	from "SysSchemaContent" content
    	join "SysSchema" sch on sch."Id" = content."SysSchemaId"
    	join "SysPackage" pack on pack."Id" = sch."SysPackageId"
    	where convert_from(content."Content", 'UTF-8') like concat('%', search_text, '%')
    	;
    END
    $$ LANGUAGE plpgsql;

    MSSQL

    /*
    	Usage: select * from udf_search_source_code('groupAnd.addItem');
    */
    ALTER   FUNCTION [dbo].[udf_search_source_code] (
    	@search_text text
    )
    RETURNS TABLE
    AS
    RETURN
    	select 
    	pack.Name as package_name,
    	sch.Name as schema_name,
    	sch.ManagerName as manager_name,
    	substring(
    		Cast(content.Content as varchar(max)), 
    		patindex(
    			concat('%',@search_text ,'%'), 
    			Cast(content."Content" as varchar(max))
    		), 
    		200
    	) as search_result
    	from SysSchemaContent content
    	join "SysSchema" sch on sch."Id" = content."SysSchemaId"
    	join "SysPackage" pack on pack."Id" = sch."SysPackageId"
    	where Cast(content.Content as varchar(max)) like concat('%', @search_text, '%');

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Infor CRM 10: Phone Number “Starts With” Search Not Working with Formatted Numbers

Infor CRM 10's Starts With search may fail to find phone numbers stored with formatting characters. Learn why this happens, how to identify affected records, and how to resolve the issue.

Increase Attachment Size Allowed in the Infor CRM SLX Web Client

It is possible to increase Infor CRM SLX's limit on the size of a file that can be uploaded by editing values in web.config file.

A Closer Look at the AI Features in Infor CRM v10

Infor CRM v10 includes several built-in Generative AI features that go beyond a simple chatbot. Here's a closer look at AI Summary, AI Assistant, AI Newsfeed, and AI-assisted email drafting.

[Webinar] Infor CRM SLX Admin Essentials: Xbar for Web and Email Marketing

On Tuesday, September 15, 2026, Infor is hosting an...

Infor CRM Mobile 4.4 Now Available: What’s New

Infor CRM Mobile 4.4 is now available for single-tenant cloud and on-premises customers. Explore business card capture, dashboards, workflows, and more.

Related Articles

Infor CRM 10: Phone Number “Starts With” Search Not Working with Formatted Numbers

Infor CRM 10's Starts With search may fail to find phone numbers stored with formatting characters. Learn why this happens, how to identify affected records, and how to resolve the issue.

Increase Attachment Size Allowed in the Infor CRM SLX Web Client

It is possible to increase Infor CRM SLX's limit on the size of a file that can be uploaded by editing values in web.config file.

A Closer Look at the AI Features in Infor CRM v10

Infor CRM v10 includes several built-in Generative AI features that go beyond a simple chatbot. Here's a closer look at AI Summary, AI Assistant, AI Newsfeed, and AI-assisted email drafting.

[Webinar] Infor CRM SLX Admin Essentials: Xbar for Web and Email Marketing

On Tuesday, September 15, 2026, Infor is hosting an administrator-focused webinar covering two areas that can help organizations...

Related Videos