having a bit of a problem in sql

i have a table and have been given a task to sort some of the fields out in the table

I have a firstname field which contains there name and all i want to have is the initial so i want to cut or trim all of the characters after the first one,, how can i do this,, ive tried to make the field smaller and isnt workin and ive also tried to use many different statements which also are not workin

another problem im having is i have a column which contains number 1-26 and i need code that will change these to letters eg

1= A
2 =B
3 =C

and so on

Please help
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:
Change first name to first character:

UPDATE SomeTable
SET SomeColumn = LEFT(SomeColumn, 1)

Numbers to letters (assumes that the column to be updated is already [n][var]char data type):

UPDATE SomeTable
SET SomeColumn = CHAR(64 + CAST(SomeColumn AS int))
WHERE CAST(SomeColumn AS int) BETWEEN 1 AND 26
you can change the number to sql by an easy update statement such as

UPDATE TableName
SET ColumnName = CASE ColumnName WHEN 1 THEN 'A'
                                                                WHEN 2 THEN 'B'
But you must be sure thath your column can hold string values... check the data type

ltrim and rtrin function do not give you what you want...


SUBSTRING(ColumnName, 1, 1) + SUBSTRING(ColumnName, PATHINDEX(' ',ColumnName) + 1, 1) +
ISNULL(SUBSTRING(ColumnName, PATHINDEX(' ',SUBSTRING(ColumnName, PATHINDEX(' ',ColumnName) + 1, LEN(ColumnName) - PATHINDEX(' ',ColumnName) + 1 ) + 1, 1) , '')
LukeConeyAuthor Commented:

ALSO i need to change names of job titles

for example

Proprietor has not got to become Business owner

how do i do that
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Patrick MatthewsCommented:

With respect, you've already asked two questions in this thread, now this is a third.


LukeConeyAuthor Commented:
im offering more points
Patrick MatthewsCommented:
For a one-off change...

UPDATE SomeTable
SET SomeColumn = 'Business owner'
WHERE SomeColumn = 'Proprietor'

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.