Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello sir.

I have an image path in database like E:/BackUpWebsites/sri/images/........jpg.

I want to remove (E:/BackUpWebsites/sri) from every row.
I have 100 rows in a table.
How can I do this?

Anybody, please help me.

Thanking you.
Posted
Updated 11-Jan-11 21:27pm
v2
Comments
Dalek Dave 12-Jan-11 3:27am    
Edited for Grammar, Syntax and Readability.

Hope this[^] will give an idea.
 
Share this answer
 
Comments
Dalek Dave 12-Jan-11 3:27am    
Good Link
Kasson 12-Jan-11 3:57am    
Thanks Dalek
Use Replace[^]
SQL
UPDATE TableName SET ColumnName = (SELECT REPLACE(ColumnName,'E:/BackUpWebsites/sri','') FROM TableName)

You can update by the following way
SQL
UPDATE TableName SET [ColumnName] = REPLACE([ColumnName],'E:/BackUpWebsites/sri','') FROM TableName

Acknowledgment - Thanks to Ankur.
 
Share this answer
 
v2
Comments
Ankur\m/ 12-Jan-11 2:14am    
The user wants to remove the text from the column. This would just select the remaining part.
thatraja 12-Jan-11 2:16am    
Oh I thought he can manage, I'll update.
Dalek Dave 12-Jan-11 3:28am    
Seems Reasonable.
justinonday 12-Jan-11 3:58am    
Good answer
DECLARE @path VARCHAR(256) -- path name
DECLARE db_cursor CURSOR FOR
SELECT ColunmName
FROM TableName
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @path
WHILE @@FETCH_STATUS = 0
BEGIN
       SELECT REPLACE(@path,'E:/BackUpWebsites/sri','') FROM TableName
       FETCH NEXT FROM db_cursor INTO @path
END
CLOSE db_cursor
DEALLOCATE db_cursor
 
Share this answer
 
Comments
Ankur\m/ 12-Jan-11 2:15am    
Correct! :)
justinonday 12-Jan-11 2:18am    
Thanks Ankur
thatraja 12-Jan-11 2:31am    
Good one man but you can do that also by single query(See my answer). Cheers. 5!
justinonday 12-Jan-11 2:56am    
Thanks Thatraja
Dalek Dave 12-Jan-11 3:27am    
Good 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