1

Basically I have a column in SQL Server that has icon image names

It's kind of like

ICON
------------
Icon001
Icon002.png
Icon003.png
Icon004.png
Icon005
Icon006.png
Icon007.png

I'm trying to figure out how I can write a script to remove all of the .png from the ones that have it

I have tried

Update [dbo].[screen].[icon] 
set ICON = ICON - '%.png%' 
where ICON LIKE '%.png%'

But that doesn't work.

Can anybody help me?

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
Derick
  • 43
  • 1
  • 5
  • 1
    Hint: [`REPLACE()`](http://msdn.microsoft.com/en-us/library/ms186862.aspx) and of course research on [previous related questions](http://stackoverflow.com/search?q=sql+server+remove+part+of+string) – Pondlife Mar 22 '13 at 21:17

3 Answers3

2

Try

... set ICON=LEFT(icon, LEN(icon)-4 ) where ICON like '%.png'
Marc B
  • 348,685
  • 41
  • 398
  • 480
2
...SET ICON = REPLACE(ICON, '.png','')

Should do the trick

Yuriy Galanter
  • 36,794
  • 12
  • 65
  • 122
0

Maybe something like

UPDATE icon SET icon = LEFT(icon, CHARINDEX('.png', icon) - 1) WHERE icon LIKE '%.png%'

A demo of something

Kermit
  • 33,206
  • 11
  • 83
  • 119