Replacing leading characters in string

How would i replace first two characters if they are zeros?


 1. 00001
 2. 00123
 3. 02451

Should be:

 1. 11001
 2. 11123
 3. 02451

EDIT: Forgot to mention i need this in select clause (in a view) Thanx.


update  YourTable
set     col1 = '11' + substring(col1, 3, len(col1)-2)
where   col1 like '00%'

In a view, you could do it like:

select   case
         when col1 like '00%' then stuff(col1, 1, 2, '11')
         else col1
from     YourTable;

Live example at SQL Fiddle.

declare @a varchar(10)

select @a='01123'

Select case when LEFT(@a,2)='00' then STUFF(@a,1,2,'11') else @a end

you can also use left method like below

select case When left(Name,2) = '00' Then stuff(Name, 1, 2, '11')
     else Name
 from YourTable

SELECT REPLACE(LEFT(MyCol,2),'00','11')+RIGHT(MyCol,3)

Need Your Help

Check to see if python script is running

python process daemon

I have a python daemon running as a part of my web app/ How can I quickly check (using python) if my daemon is running and, if not, launch it?

When exactly is it leak safe to use (anonymous) inner classes?

java android memory-leaks inner-classes

I have been reading some articles on memory leaks in Android and watched this interesting video from Google I/O on the subject.