Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add zeros in front of a text field in an access table

Tags:

sql

ms-access

I have an access table with a text field. It has alpha numeric values. But i want all values to be minimum 3 digit. so i want to add zeroes in front of all single or two digit values

.

5  must become 005
89 must become 089

how do i write a query to update all values in the table.

thanks tksy

like image 673
tksy Avatar asked Jan 22 '26 00:01

tksy


1 Answers

The key is to add as many zeros as needed to take the length up to 3.

UPDATE yourTable
SET YourField = LEFT("00", 3-LEN(YourField)) + YourField
WHERE LEN(YourField)<3 AND Len(YourField)>0
like image 92
mdma Avatar answered Jan 25 '26 23:01

mdma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!