Link to home
Create AccountLog in
Avatar of najixp
najixp

asked on

one more question MR.liviutudor or any Available expert on the qsl statement

i am doing "...order by cStr(partname)"
it works fine as string sorting can you please tell me what to do if i need to sort useing the ACS() or cLng what to do cause its not working
Avatar of liviutudor
liviutudor

well, if partname is already a string/text datatype then you don't need the CStr(partname) -- you could simple say ...order by partname
similar, if the column you want to order by is a number, you don't need to use CLng() -- simply just order by <column name>
Last but not least: I gather you are using ACCESS?
Avatar of najixp

ASKER

you i am useing msacces but visual basic inteface
the fact is the column is a string/text datatype i want to sort it useing the ascii of the string useing the sql statement
Is the part name a number by any chance?
well, like i said, if the column is a string, you do not need the CStr() function and it will sort it in alphabetical order -- is this not what you want?
Numerical order being different from alphabetical order could be your problem.  Depending on which one you want you can use CLng or CStr in the order by section but that looks like what you've already done.
The ASC() of a character is the numerical code that represents the character.  I don't think you can ASC("WORD") and sort.

If you want a numerical sort of the query string use CLng as long as there are no non numerical characters.  If you have one partname in your list that has a non numerical character your stuck with alphabetical order and or would have to jump through major hoops to get whatever results your looking for.
Heres a crazy idea:

Bring in your Numerical first then bring in your NonNumerical and put them together with some kind of custom sorting routine.
     
Avatar of najixp

ASKER

hi i am back
all i need is to sort the string/text datatype column useing their ascii in sql statement
what exactly do you mean by "using their ASCII"???? :O
alphabetical sort is sorting them in order of their ASCII code! And the ASCII code is such that the code for 'a' is smaller than the code for 'b' which is smaller than the code for 'c' and so on...
According to Wikipedia (http://en.wikipedia.org/wiki/ASCII) ASCII is the text representation of standard printable characters.  So based on wikipedia's definition of ascii you want a text string sort or alphabetical sort.  Simply use the following:

SQLQuery = "SELECT CStr(PartNumber) as MyStringPartNumber FROM YourTable
                    ORDER BY MyStringPartNumber"
Now.. if your wanting to sort by the numerical code representation of each character in each word of every record PartNumber... thats crazy man!!  But I dig it ya know.
To do that you would have to be able to seperate each character of each word, convert it to the ASCII code representation and perform the sort for each word based on each ASCII code in that word for all records.  I'm not sure you can do that with the limitations of SQL Query Language.  I also think that if you were successfull that it would be a monster from Planet X.  I don't think I really want to spend the time to figure that one out and so I yeild to those who have alot more time on their hands.  

Also,I think it would be impossible if all PartNumbers didn't have the same number of characters, however, I'm not positive of this.
ASKER CERTIFIED SOLUTION
Avatar of abbdan
abbdan

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Wow.. was not expecting that one to be the solution for you.  Glad you could use it.