alphabetical order not working
I have customer details , have lastname column ,
Some of records contain white space in the name front and back ,开发者_StackOverflow社区
i want to do the alphabetical order , but not working properly,
plz chk this screen shot , i cant able to guess wha tis the exact reason ,
space
is considered as character, then it will taken into account when you sort the data.
you might want to trim()
data before inserting into database.
leonardys is right, you should trim all your inputs before they even go into the database. However, this alone will not solve your problems with people putting punctuation characters and the such in front of their name.
Assuming this database reflects user input, you should do a more thorough input validation. Allowing only alphabetical input (with accents as well if needed) is for example a good solution (given that you expect real names only). Instead of trying to eliminate the unwanted characters, restrict the input to only the allowed ones. Space however, should not be restricted as many valid names contain spaces (e.g. Ann Mary), and therefore you should trim your input after it has been entered.
As for updating the database, that would be tricky. Trimming will only solve the spaces problem. If this is user based data, try asking the ones with illegal characters to update their profile and not let them access the site until they do so. You could excuse it as a database upgrade or some other technical issue.
Hope I helped.
精彩评论