How can i get a name collumn form a table first and last character io uppercase and remain in lower. [Resolved]

Posted by Kumarkrishna184 under Sql Server on 3/25/2016 | Points: 10 | Views : 353 | Status : [Member] | Replies : 5
How can i get a name column form a table first and last character in uppercase and remain in lower.

Thanks,

Thanks and Regards,
Krishna Kumar



Responses

Posted by: Rajnilari2015 on: 3/26/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Try this

DECLARE @T Table(Name Varchar(20))

INSERT INTO @T
SELECT 'krishna' UNION ALL
SELECT 'rajni' UNION ALL
SELECT 'ravi'

SELECT
OriginalNAME =Name
,ModifiedName=UPPER(LEFT(Name,1)) + SUBSTRING(NAME, 2, LEN(Name)-2) + UPPER(RIGHT(NAME,1))
FROM @T


Output
---------


OriginalNAME	ModifiedName

krishna KrishnA
rajni RajnI
ravi RavI


You can also use CONCAT function of SQL Server 2012 (Denali)

ModifiedName=CONCAT(UPPER(LEFT(Name,1)),SUBSTRING(NAME, 2, LEN(Name)-2),UPPER(RIGHT(NAME,1)))


--
Thanks & Regards,
RNA Team

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 3/25/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
Please provide an example with sample input and expected output

--
Thanks & Regards,
RNA Team

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kumarkrishna184 on: 3/26/2016 [Member] Starter | Points: 25

Up
0
Down
Ok Sir..

Thanks and Regards,
Krishna Kumar

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kumarkrishna184 on: 3/26/2016 [Member] Starter | Points: 25

Up
0
Down
If there is a Employee table with eid,name,salary,dept column
in name column if value is
krishna
rajni
ravi
like this
i want name should look like following..
KrishnA
RajnI
RavI
means first and last character of namne should be in uppercase and remaining should be lowercase

Thanks and Regards,
Krishna Kumar

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kumarkrishna184 on: 3/26/2016 [Member] Starter | Points: 25

Up
0
Down
Wow, thanks sir...

Thanks and Regards,
Krishna Kumar

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response