SQL Replace question

Hi
I ahve something like PRLT12345 in a field in records.
i need to replace the PRL with PR.
Whats the ebst way to do this??
Cheers
Mat
funkkubeAsked:
Who is Participating?
 
Rajkumar GsConnect With a Mentor Software EngineerCommented:

UPDATE YourTable 
	SET YourColumn = REPLACE(YourColumn, 'PRL', 'PR')
	WHERE YourColumn = 'PRLT12345'

Open in new window

0
 
Om PrakashCommented:
To View
declare @t varchar(100)
set @t  = 'PRLT12345'
select replace(@t, 'PRL','PR')

Or To update:
Update your_table set field = replace(field, 'PRL','PR')

0
 
FemSteenkampCommented:
use patindex and substring if teh replacement is mid string to first find it and then exlcude it

or if it is always first in the string
set field = 'PR' + substring('PRLT12345',4,len('PRLT12345'))

or
replace('PRLT12345','PRL','PR')

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.