Update a field with truncated value form another field.

Copper Contributor

I’m trying to update a field in a table based on the value in another field in the same table.


table = customers

field 1 = customer 

field 2 = code 

I have three records in the customers table - field ref = customer

1. Smith and sons

2. Smiths industries

3. Smiths Lmited


i want to update customers table setting the code field to have the first three letters of the customer field then serial reference 

so the three records containing the code field would read 

1. SMI001

2. SMI002

3. SMI003


If anyone could help me with the correct mssql syntax then I would appreciate it. 

best regards Darrell

2 Replies

@F1-bc , use the LEFT (Transact-SQL) - SQL Server | Microsoft Learn function to get the first 3 letters.

For a more details answer, post more details: Please post table design as DDL, some sample data as DML statement and the expected result.

@olafhelper Thanks appreciate you replying. I'll give this a try as well.