Russ Suter
asked on
Pad imported text with trailing zeros
I'm importing some text from an excel spreadsheet and I need to make sure a certain field is 16 characters long. Sometimes, the excel spreadsheet only has 14 characters in it. In this case, I just need to pad the text with trailing zeros. How can I do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
After the import you could run an update like:
first,
SELECT field, LEFT(field + '0000000000000000', 16)
FROM table
WHERE LEN(field) < 16
if that looks good then,
UPDATE table
SET field = LEFT(field + '0000000000000000', 16)
WHERE LEN(field) < 16
first,
SELECT field, LEFT(field + '0000000000000000', 16)
FROM table
WHERE LEN(field) < 16
if that looks good then,
UPDATE table
SET field = LEFT(field + '0000000000000000', 16)
WHERE LEN(field) < 16
1. Use a temp table to hold the data and then use a select query to insert the data
2. Directly Query from the Excel sheet
http://sequelserver.blogspot.com/2006/04/update-table-from-excel-sheet-using.html