Add EA to the start of a field in a column

  • I am new to sql and would like your help. I have a table that lists an payroll reference number for all the workers in the business. for example

    Emma Davies 01234568

    Jo Bloggs 45685214

    I need to update the Payroll_reference filed so they all start with EA. So after update is will be

    Emma Davies EA01234568

    Jo Bloggs EA45685214

    I have used this but it did not work. Any ideas please?

    Update pdcontacts

    set Payroll_ref = 'EA' + 'Payroll_ref'

  • emdavies82 (10/15/2013)


    I am new to sql and would like your help. I have a table that lists an payroll reference number for all the workers in the business. for example

    Emma Davies 01234568

    Jo Bloggs 45685214

    I need to update the Payroll_reference filed so they all start with EA. So after update is will be

    Emma Davies EA01234568

    Jo Bloggs EA45685214

    I have used this but it did not work. Any ideas please?

    Update pdcontacts

    set Payroll_ref = 'EA' + 'Payroll_ref'

    You've quoted 'Payroll_ref', so that makes it a literal string. Your essentially said: -

    Update all Payroll_ref columns to "EAPayroll_ref".

    Try: -

    BEGIN TRANSACTION;

    UPDATE pdcontacts

    SET Payroll_ref = 'EA' + Payroll_ref;

    --Check results

    SELECT *

    FROM pdcontacts;

    --Rollback changes

    ROLLBACK;

    --COMMIT;

    --Comment out ROLLBACK and uncomment COMMIT when you're happy that this does what you expect.


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Thank you so much for the fast response 🙂

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply