Help please, total newbie trying to learn. Trying to Change the first character in a field

  • Hi All,

    SELECT   Timesheet_Number, Employer_Ref, Personnel_Ref, Division, Department, Job_Location, Tax_Year, Tax_Period
    FROM    Timesheets
    WHERE   (Timesheet_Number LIKE 'EPCB%')

    This returns 1000 timesheet numbers starting with 'EPCB'     (Example number is 'EPCB066166')
    I want to change the 'EPCB' at the start to read 'HPCB' instead. (Result number would be 'HPCB066166')

    How do I do this please?

    Thanks
    Emma

  • UPDATE Timesheets
    SET Timesheet_Number = STUFF(Timesheet_number,1,4,'HPCD')
    WHERE Timesheet_Number LIKE 'EPCB%'

    Make sure you understand what the STUFF function does before you use this in production.  You're the one who'll be supporting it, so you need to know how it works!

    Edit - corrected typo in code

    John

  • Thank you for your help, I will research STUFF now

    Thanks

  • For reference: STUFF

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

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