Trigger to capitalize

Write a trigger that will capitalize the first and last names of customers inserted into the Persons table.  Write one or more statements that will fire the trigger when a record is inserted.
jphilliAsked:
Who is Participating?
 
Lee SavidgeCommented:
I've seen this request a number of time and you will have trouble. In principle your code is simple:

declare @firstname nvarchar(100), @lastname nvarchar(100)

select @firstname = 'fred', @lastname = 'bloggs'

select upper(left(lower(@firstname), 1)) + right(@firstname, len(@firstname) - 1), upper(left(lower(@lastname), 1)) + right(@lastname, len(@lastname) - 1)



Taking Western style names as examples and you'll run into problems:

O'Toole
McDonald
MacIntyre
Macintyre
van den Heever
Van De Casteele

etc.

There are always exceptions to the rule.
0
 
Lee SavidgeCommented:
Double-barrelled names cause issues as well and there are triple barrelled ones around.
0
 
sarabhaiCommented:
can u specify the table on that trigger will fire and other table name in that data will save.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.