April 25, 2013 at 1:49 am
Dear,
I have a product table containing columns ProdID, ProdName and ...
The data type of ProdID is varchar(10). It contains data like 1,2,3 and so on.
If I execute the select statement,
select prodid from Product where (ProdId between '1000' and '11500') order by ProdId;
I get the result like,
1000
10001
10002
10003
10004
1001
1002
.
.
.
11001
11002
1101
1102
.
.
.
11501
But I want that it should be like,
1000
1001
1002
1101
1102
10001
10002
10003
10004
11001
11501
What can I do for it. Please help me.
Regards,
Akbar
April 25, 2013 at 2:15 am
Try converting it to int and sort.
Regards
Durai Nagarajan
April 25, 2013 at 11:55 am
This is a common problem when numeric data is stored as character and durai has posted one solution. Often in these types of applications the application will prepend 0's to the numeric value to get it sorting as desired as well. Also be aware that any index on ProdID will be sorted the way SQL Server is returning the data as well.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
April 26, 2013 at 12:59 am
In addition to jack's comments.
why dont you user in or bigint and you can use identity as well.
Index will have greater effect on usage of between.
Regards
Durai Nagarajan
April 27, 2013 at 10:01 pm
@Durai, you are right and your idea worked.
Thank you @Durai and Jack.
Actually the application was developed six years ago and I am working only eight months on it. So it will take time for me to change even its difficult.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply