Remove numbers from mixed string in SQL


DECLARE @mixedNumStr varchar(500)

SET

@mixedNumStr = ‘FOSTER,ROBERT:3244472~SMITH,PATRICK A:39766516~WINDER,BARRY L:3246852~MEYER,JIM W:3256885~HOLD,JERALD:3278662~LEAMAN,MICHAEL P:31555’;

BEGIN

WHILE

PATINDEX(‘%[0-9]%’,@mixedNumStr)> 0

SET

@mixedNumStr = Replace(REPLACE(REPLACE(@mixedNumStr,SUBSTRING(@mixedNumStr,PATINDEX(‘%[0-9]%’,@mixedNumStr),1),),‘~’,‘ / ‘),‘:’,)

END

PRINT

@mixedNumStr

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s