SQLUSA

Microsoft SQL Server 2005 Best Practices

Microsoft SQL Server 2000 Best Practices

How to avoid using substring in a WHERE clause?

 

Using substring in a WHERE clause may cause table scan. That would be very slow on a large table of millions of rows. In some cases the like matching function can be used without causing table scan. Example:

 

Instead

WHERE SUBSTRING(ProductName,1,3) = 'net'

Try this

WHERE ProductName LIKE 'net%'

 

Best in the World in SQL Server Training
 
SQLUSA.com Home Page