Trigger to capitalize

Posted on 2012-08-15
Last Modified: 2012-08-16
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.
Question by:jphilli
    LVL 25

    Accepted Solution

    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:

    van den Heever
    Van De Casteele


    There are always exceptions to the rule.
    LVL 25

    Expert Comment

    by:Lee Savidge
    Double-barrelled names cause issues as well and there are triple barrelled ones around.
    LVL 9

    Expert Comment

    can u specify the table on that trigger will fire and other table name in that data will save.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
    Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now