devxlogo

Determining Visual Fox Pro Field Length

Determining Visual Fox Pro Field Length

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

See also  5 Tips for Choosing the Right Medical Software for Your Practice
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist