December 7, 2015 at 11:50 am
I need to change the first and last letter to upper case . The below piece of the code works , just wanted to know if there is a better way of doing it .
declare @name varchar(100)
Select @name = 'test'
print Upper(substring(@name,1,1))+Substring(@name,2,Len(@name)-2) + Upper(substring(@name,(len(@name)-0),Len(@name)))
December 7, 2015 at 1:52 pm
3 possible options. I used LOWER, but I'm not sure if you need it.
PRINT UPPER(LEFT(@name,1)) + LOWER( SUBSTRING(@name,2,Len(@name)-2)) + UPPER(right(@name,1))
PRINT STUFF( STUFF( LOWER(@Name), 1, 1, UPPER(LEFT(@name,1))), LEN(@name), 1, UPPER(RIGHT(@name,1)))
PRINT UPPER(LEFT(@name,1)) + STUFF( LOWER(SUBSTRING(@name,2, 100)), LEN(@name) - 1, 1, UPPER(RIGHT(@name,1)))
December 8, 2015 at 12:29 am
You've said letter.
What about strings like Select @name = 'test2' or Select @name = ' test' , what result is expected?
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply