SQL SERVER

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
LukeConeyAsked:
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
0
tigin44Commented:
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'
                                                                ---------
                                  END
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...

AND A CODE L0KE THE ONE BELOW CAN G0VE YOIU THE 0N0T0ALS...

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) , '')
0
LukeConeyAuthor Commented:
THANKS FOR THAT

ALSO i need to change names of job titles

for example

Proprietor has not got to become Business owner

how do i do that
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Patrick MatthewsCommented:
LukeConey,

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

Regards,

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

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

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.

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.