StrataFrame Forum

mask to insert spaces before text?

http://forum.strataframe.net/Topic16583.aspx

By Fabian R Silva, - - 5/26/2008

I have certain codes (example: customer code) that can have numbers or alphanumerical characters example "AB123" or "123" or "123AB"



If I save some customer codes like "1" "2" and "11", when I try to order by this field the "11" will be on 2nd place



1,

11

2



only if I put a space before the number will be orderer ok ( " 1", " 2", "11")



1

2

11



what do you recommend to do ? can I only add spaces when I like to persist the code that a user enter on the field to the DB to order it correctly? how is the best to do this?

Thanks for any suggestion.
By Edhy Rijo - 5/26/2008

Hi Fabian,

I have done that but in VFP.  What I did was to convert or cast the field to integer so it will sort the way I needed to.  I think you may do something like that to get the proper sorting by casting the field, but keep in mind that when you cast values like ABC will have no meaning, only the digits will be casted.

By Trent L. Taylor - 5/26/2008

You can case it as Edhy mentioned, or perform the query and pad the results in the off chance that you have an illegal integer value which would then result in an error.  So I would probably just create a query that brings the data back with the padding versus trying to manage this within the BO itself.  This would also be the fastest in regards to performance.