我有一个具有以下结构的表
LanguageName |Code
----------------|----
Abkhaz |ab
Afar |aa
Afrikaans |af
Akan |ak
我有大约190个类似的行。
而且,
我需要将每一行更新为大写第一个字母 每行的列代码。
所以,结果将是:
LanguageName |Code
----------------|----
Abkhaz |Ab
Afar |Aa
Afrikaans |Af
Akan |Ak
如何在SQL-Server中实现这一目标?
答案 0 :(得分: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
答案 1 :(得分:1)
update YourTable set
LanguageName = stuff(LanguageName, 1, 1, upper(left(LanguageName,1))),
Code = stuff(Code, 1, 1, upper(left(Code,1)))