Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Replacing charecters

Author  Topic 

scelamko
Constraint Violating Yak Guru

309 Posts

Posted - 2005-03-30 : 17:02:59
Guys,
I have a column of datatype char(9) which has values like

0000234-A, 00002345A

it has these pairs with alphabets attached to end all the way from A to T
like from

0000234-A, 00001212A to 0000454-T, 00001212T

I want to replace the orccurence of these alphabets with numeric codes
for example -A , A with 02; -B, B with 03 ...

I have tried using replace function but I am looking for a generic code which does the above manipulation instead
of writing a statement for each alphabet from A to T

Any suggestions/inputs would be helpful

Thanks

rfrancisco
Yak Posting Veteran

95 Posts

Posted - 2005-03-31 : 18:22:02
To convert the alphabets to numeric codes, you can use this:

ASCII(<Letter>) - 64

This will translate letter A to 1 and so on. Just convert it back to character so that you can replace the original value.
Go to Top of Page
   

- Advertisement -