Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: SQL
hi i have delete query using substring
delete From [table] where SUBSTRING([field],1,CHARINDEX(N'',[field])-1) = 7
the query loops through millions of records,and takes long time,any sugesttion of tuning the query,(the table does not contain indexing or constrains)
Posted 6-Dec-12 2:36am
RobBranaghan at 6-Dec-12 8:45am
So you want to delete from the table where the field contains a 7?
BC @ CV at 6-Dec-12 11:29am
Since SQL Substring() returns a varchar, nvarchar, text, ntext, varbinary or image why are you comparing it to the number 7? It would be easier to help you if you would state what you are trying to accomplish.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can create a persisted computed column based on the substring formula and compare that column as number 7. I would say if you are sure that it would be number cast the substring output to int, which will again make it faster.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100