Solved

lower case on last name

Posted on 2013-05-22
5
345 Views
Last Modified: 2013-05-22
Runing the following script to update first and lastname


update dbo.mytable$
set       firstname = Replace(Firstname,reverse(left(reverse(firstname),len(firstname)-1)),  reverse(lower(left(reverse(firstname),len(firstname)-1)))),
lastname = Replace(Lastname,reverse(left(reverse(Lastname),len(Lastname)-1)),  reverse(lower(left(reverse(Lastname),len(Lastname)-1))))
where LastName = 'PIZER'


result I am getting on lastname is =  PIzer
I am expecting lastname to be Pizer

 where have i gone wrong.
0
Comment
Question by:Amanda Walshaw
5 Comments
 
LVL 13

Assisted Solution

by:Koen Van Wielink
Koen Van Wielink earned 167 total points
ID: 39189847
Hi Flyfish,

When I run the exact script I get the expected result. Try this test script below:

Create table #temp
(lastname nvarchar(100))

insert into #temp
values ('PIZER')

Select lastname = Replace(Lastname,reverse(left(reverse(Lastname),len(Lastname)-1)),  reverse(lower(left(reverse(Lastname),len(Lastname)-1))))
from #temp

drop table #temp

Open in new window


Rgds,

Kvwielink
0
 
LVL 57

Assisted Solution

by:Raja Jegan R
Raja Jegan R earned 166 total points
ID: 39189852
Try this which should work..

update dbo.mytable$
set firstname = UPPER(substring(firstname, 1, 1)) + LOWER(substring(firstname, 2, LEN(firstname)))
    ,lastname = UPPER(substring(lastname, 1, 1)) + LOWER(substring(lastname, 2, LEN(lastname)))
where LastName = 'PIZER'
0
 
LVL 48

Accepted Solution

by:
PortletPaul earned 167 total points
ID: 39189859
declare @lastname varchar(80) = 'PIZER'

select
  lastname = substring(@lastname,1,1) + lower(substring(@lastname,2,80))
0
 
LVL 13

Expert Comment

by:Koen Van Wielink
ID: 39189888
Hi Flyfish,

Just wondering if you might have some spaces at the end of the name.
Try to put the lastname column between trim statements:

LTRIM(RTRIM(lastname))

By the way, I'm feeling really stupid seeing how complicated my method was to change the uppercase to lowercase....
0
 
LVL 9

Expert Comment

by:mimran18
ID: 39189914
Please use Datalength function instead of LEN function
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
2016 SQL Licensing 7 41
transaction in asp.net, sql server 6 33
Increment column based of a FK 8 22
PROPERCASE SCRIPT IN SQL 3 7
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question