Click here to Skip to main content
12,700,567 members (32,878 online)
Rate this:
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 3:36am
RobBranaghan 6-Dec-12 8:45am
So you want to delete from the table where the field contains a 7?
BC @ CV 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2017
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