Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to store decimal with letters and then display 1

Status
Not open for further replies.

jsteiner87

Programmer
Oct 9, 2003
76
US
I have a listing of items in a database and they have section numbers that are attached to these items. For example:

1.10 Item #1
1.20 Item #2
2.24 Item #3
11.00 Item #4

I currently have these stored as a decimal. Now I need to add letters onto some of these decimals.

1.10 Item #1
1.20 Item #2
2.24 Item #3
2.24n Item #5
11.00 Item #4

If I store the items as varchar they would sort like this.

1.10 Item #1
1.20 Item #2
11.00 Item #4
2.24 Item #3
2.24n Item #5

How can I store these section numbers and have a letter in with it and sort them in a numeric order?
 
You could create a seperate field in your database table for storing the letters that you need to append.
 
change them to varchar. When you sort a varchar column you can just do

ORDER BY yourvarcharcolumn + 0

That will force correct ordering of your column.
 
The + 0 fools the database into thinking the data is in integer format it then sorts the data accordingly. Not sure it works outside of mysql.
 
Used it in my PHP code and worked very well, thanks for the help.
 
Cheers Rudy. I think I've been here a long time ago. Saw something on your site recently and ended up here.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top