| Author |
Topic |
|
Velnias
Yak Posting Veteran
58 Posts |
Posted - 2010-03-31 : 06:19:53
|
| Hi I haveselect distinct cust_disc_cat from tblDiscounts_GoldDistributorsId like to order by this columns as INT but its a VARCHARso i get 1112etcid like1211 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-03-31 : 06:26:03
|
| select distinct cust_disc_cat from tblDiscounts_GoldDistributorsorder by cast(id as int)Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
Velnias
Yak Posting Veteran
58 Posts |
Posted - 2010-03-31 : 06:37:54
|
| I tried thisSELECT DISTINCT CUST_DISC_CATFROM tblDiscounts_GoldDistributorsORDER BY CAST(CUST_DISC_CAT AS int)But got error order by item must appear in select list |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2010-03-31 : 06:53:17
|
try thisSELECT T.CUST_DISC_CATFROM (SELECT DISTINCT CUST_DISC_CAT FROM tblDiscounts_GoldDistributors ) TORDER BY CAST(CUST_DISC_CAT AS int) |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-03-31 : 06:55:26
|
| select * from(select distinct CUST_DISC_CAT from tblDiscounts_GoldDistributors ) as a order by cast(CUST_DISC_CAT as int)Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-03-31 : 06:59:29
|
| Use Group by, Better performance then aboveselect CUST_DISC_CAT from tblDiscounts_GoldDistributorsgroup by CUST_DISC_CAT order by cast(CUST_DISC_CAT as int)Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
Velnias
Yak Posting Veteran
58 Posts |
Posted - 2010-03-31 : 07:04:31
|
| That did the trick cheers |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
PackRat
Starting Member
26 Posts |
Posted - 2010-03-31 : 10:53:25
|
quote: Originally posted by madhivanan <<Id like to order by this columns as INT but its a VARCHAR>>If you are going to store only numbers, better you change the datatype to INTAlso referhttp://beyondrelational.com/blogs/madhivanan/archive/2008/07/21/ordering-interger-values-stored-in-varchar-column.aspxMadhivananFailing to plan is Planning to fail
...and if for some reason you can't switch it to a numeric data type consider adding something like WHERE ISNUMERIC([col])=1to ensure that you don't error out if there is string data intermingled_____________________________wrote this on my TRS-80 COCO4<PakRat/> |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2010-03-31 : 11:01:22
|
quote: Originally posted by PackRat
quote: Originally posted by madhivanan <<Id like to order by this columns as INT but its a VARCHAR>>If you are going to store only numbers, better you change the datatype to INTAlso referhttp://beyondrelational.com/blogs/madhivanan/archive/2008/07/21/ordering-interger-values-stored-in-varchar-column.aspxMadhivananFailing to plan is Planning to fail
...and if for some reason you can't switch it to a numeric data type consider adding something like WHERE ISNUMERIC([col])=1to ensure that you don't error out if there is string data intermingled_____________________________wrote this on my TRS-80 COCO4<PakRat/>
ISNUMERIC() is not safe. See this article: [url]http://classicasp.aspfaq.com/general/what-is-wrong-with-isnumeric.html[/url]Harsh Athalyehttp://www.letsgeek.net/ |
 |
|
|
|