When I execute a query " select ('NILESH') " in sql server 2008 it gives the output as NILESH.
But I want oupput as there should be only first letter capital rather than all the letters like I want o/p should be like " Nilesh " i.e. only first letter capital and others are small. How to write query for this.
Loading
Shankar MPosted Sep 17, 2013, 7:26 AM
There is no Initcap function in Sqlserver as in Oracle. Instead we can write a custom function to achieve the same functionality.
DECLARE @NAME VARCHAR(10)
SET @NAME = 'NILESH'
SELECT UPPER(SUBSTRING(@NAME,1,1)) + LOWER(SUBSTRING(@NAME,2,LEN(@NAME)))
Iftikar HussainPosted Sep 17, 2013, 7:21 AM
Try like this
select UPPER(LEFT('NILESH',1))+lower(SUBSTRING('NILESH',2,len('NILESH')))
Regards,
Iftikar
Sanjeeb LenkaPosted Sep 17, 2013, 7:20 AM
try this
DECLARE @name nvarchar(20)='NILESH'
SELECT UPPER(LEFT(@name,1))+LOWER(SUBSTRING(@name,2,LEN(@name)))