Aufal Ahdy
Aufal Ahdy

Reputation: 105

SQL Server how to change 1 letter from lower case into upper case?

I have column that contains many row. Each row has value about 3 words. I want to change first letter of that value into upper case. Only first letter, example abc def ghi into Abc def ghi. Please help me. Thank !!

Upvotes: 2

Views: 5499

Answers (5)

RNA Team
RNA Team

Reputation: 279

Also this worked

DECLARE @val VARCHAR(20) = 'abc def ghi'
SELECT UPPER(SUBSTRING(@val,1,1))+SUBSTRING(@val,2,LEN(@val)-1)

Upvotes: 0

Aufal Ahdy
Aufal Ahdy

Reputation: 105

DONE !! thx all

UPDATE table SET column= CONCAT(upper(LEFT(column, 1)), 
                         SUBSTRING(column, 2,100));

Upvotes: 2

Nguyễn Hải Triều
Nguyễn Hải Triều

Reputation: 1464

You can try this:

DECLARE @val VARCHAR(100) = 'abc def'
SELECT UPPER(LEFT(@val,1)) + SUBSTRING(@val,2,LEN(@val))

Upvotes: 1

You can use LEFT and RIGHT in following:

DECLARE @val VARCHAR(100) = 'abc def ghi'
SELECT UPPER(LEFT(@val,1)) + RIGHT(@val, LEN(@val) -1)

Upvotes: 1

ughai
ughai

Reputation: 9890

Since you only want only first character in caps, You can use STUFF with UPPER and LEFT like this

DECLARE @val VARCHAR(100) = 'abc def ghi'
SELECT STUFF(@Val,1,1,UPPER(LEFT(@Val,1)))

OUTPUT

Abc def ghi

Note: If you have spaces at the start of the string use LTRIM before other operations

Upvotes: 4

Related Questions