Question:
Is there a way, using Visual FoxPro, to determine the maximum number of characters (not spaces) in a field? I am working with a table that has over 3 million records. I know the field length for lastname and firstname could be reduced to save space. To do this, I need to know the longest firstname and lastname character strings that have letters in them.
Answer:
Run a single query to find out this information. This is taking advantage of what are called “aggregate” functions in SQL (the MAX aggregate function in this case).
This code creates a cursor with some information and then shows the query to run against it. This will tell you the maximum number of characters in each of the fields, with the trailing spaces trimmed away. Put the code into a PRG file and run it.
create cursor rick(fname c(20),lName c(20))insert into rick (fname,lname) value ("Rick","Hodder")insert into rick (fname,lname) value ("Charley","Gunn")insert into rick (fname,lname) value ("ZipD","DooDah")select MAX(LENC(RTRIM(fname))) AS sizefname, MAX(LENC(RTRIM(lname))) AS sizelname from rick