Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
Rob Branaghan 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

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900