DF042: The CHARINDEX function is used in the SELECT, UPDATE, or DELETE statement.

The topic describes the DF042 T-SQL code analysis rule.

Category

BEST PRACTICE

Message

The CHARINDEX function is used in the SELECT, UPDATE, or DELETE statement.

Description

Avoid using the CHARINDEX function in filtering clauses of the SELECT, UPDATE, and DELETE statements.

Additional information

Using CHARINDEX in filtering clauses may lead to inefficient query execution, especially on large datasets. This is because CHARINDEX operates on each row individually, potentially resulting in poor performance due to excessive string manipulation.

Noncompliant code example

SELECT CHARINDEX('bicycle', 'Reflectors are vital for bicycle safety.') AS char_index
FROM dbo.DemoTable
GO

Compliant solution

DECLARE @char_index BIGINT;
SET @char_index = CHARINDEX('bicycle', 'Reflectors are vital for bicycle safety.');
SELECT @char_index AS char_index;
GO

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All Features

All features

Get acquainted with the rich features and capabilities of the Studio in less than 5 minutes.
Request a demo

Request a demo

If you consider employing the Studio for your business, request a demo to see it in action.
Ready to start using dbForge Studio for SQL Server?