1

I have a table that has the following structure

LanguageName    |Code 
----------------|----
Abkhaz          |ab
Afar            |aa
Afrikaans       |af
Akan            |ak

I have about 190 similar rows.

And,

I need to update each row as Capitalizing the first letter of the Column Code for each row.

So, that the result would be:

LanguageName    |Code 
----------------|----
Abkhaz          |Ab
Afar            |Aa
Afrikaans       |Af
Akan            |Ak

How can I achieve this in SQL-Server?

4

2 回答 2

2
update your_table
set Code = UPPER(substring(code, 1, 1)) + substring(code, 2, 1)

编辑

单步:

substring(code, 1, 1)   -> extracts the 1st character from code column
substring(code, 2, 1)   -> extracts the 2nd character from code column
UPPER()                 -> uppers the 1st substring
substring1 + substring2 -> puts them together
set code =              -> the result of the above for every row
于 2012-07-11T10:39:59.353 回答
1
update YourTable set
  LanguageName = stuff(LanguageName, 1, 1, upper(left(LanguageName,1))),
  Code = stuff(Code, 1, 1, upper(left(Code,1)))

SE-数据

于 2012-07-11T10:40:15.287 回答