TRANSFORM(draw_no, "9999999") does not make the column to remove the letter from the end but at the same time display the whole value in this field
Oh, yes, I see why. What I should have said is to replace it with [tt]TRANSFORM(
VAL(draw_no
), "9999999")[/tt]
Since your aim is to learn these "tricks"[tt]
*[/tt], let me explain. VAL() converts a string to a numeric, up to and excluding the first non-numeric character. So "118845A" will be converted to a numeric 118845, and "8346A" to 8346.
TRANSFORM() converts that numeric value back to a string. The second parameter, that is the "9999999", says that the result of the conversion will consist of a string seven characters wide. So, that's the result you want.
Now, the point is that, in a SQL SELECT statement, if a result field is based on an
expression (as opposed to a field in the input table), then VFP has to determine how wide to make the field in the result set. It does that by looking at the width of the field
in the first record of the result set. If other records contain larger values, they will get truncated. That shouldn't happen with my code, because the "9999999" forces all the values to the same width.
That said, Olaf was using PADR() to force the result set to a given width, which is also correct. I'm not sure why you were not getting the correct result with that code, which is why I said I wasn't sure if my solution was correct.
Hope this makes sense.
([tt]
*[/tt] They are not "tricks" to us, of course, but rather the tools of the trade.)
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads