select * from SaleVolumn order by Sales DESC
for example i have 3 value
132
222
1122
now it order by
222
132
1122
but what i want is the biggest come first.
what should i do?
****************************************
*
* This message was posted via http://www.droptable.com
*
* Report spam or abuse by clicking the following URL:
* [url]http://www.droptable.com/Uwe/Abuse.aspx?aid=b1aa3babb0da40f38a18f948b92aa1e1[/u
rl]
****************************************
*Is the datatype of the Sales coulmn char or varchar?
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com
"Gabe Wong via droptable.com" <forum@.droptable.com> wrote in message
news:b1aa3babb0da40f38a18f948b92aa1e1@.SQ
droptable.com...
> select * from SaleVolumn order by Sales DESC
>
> for example i have 3 value
> 132
> 222
> 1122
> now it order by
> 222
> 132
> 1122
> but what i want is the biggest come first.
> what should i do?
> ****************************************
*
> * This message was posted via http://www.droptable.com
> *
> * Report spam or abuse by clicking the following URL:
> *
http://www.droptable.com/Uwe/Abuse...a18f948b92aa1e1">
> ****************************************
*|||Looks like your Sales column could be a VARCHAR/CHAR rather than a numeric
type. If so, it will make sense to change this in your table structure but
for now you can do:
SELECT *
FROM SaleVolume
ORDER BY CAST(sales AS INTEGER) DESC
David Portas
SQL Server MVP
--sql
Showing posts with label example. Show all posts
Showing posts with label example. Show all posts
Monday, March 26, 2012
Order By in Biggest Value
Order By in Biggest Value
select * from SaleVolumn order by Sales DESC
for example i have 3 value
132
222
1122
now it order by
222
132
1122
but what i want is the biggest come first.
what should i do?
*****************************************
* This message was posted via http://www.sqlmonster.com
*
* Report spam or abuse by clicking the following URL:
* http://www.sqlmonster.com/Uwe/Abuse...18f948b92aa1e1
*****************************************
Is the datatype of the Sales coulmn char or varchar?
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com
"Gabe Wong via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:b1aa3babb0da40f38a18f948b92aa1e1@.SQLMonster.c om...
> select * from SaleVolumn order by Sales DESC
>
> for example i have 3 value
> 132
> 222
> 1122
> now it order by
> 222
> 132
> 1122
> but what i want is the biggest come first.
> what should i do?
> *****************************************
> * This message was posted via http://www.sqlmonster.com
> *
> * Report spam or abuse by clicking the following URL:
> *
http://www.sqlmonster.com/Uwe/Abuse...18f948b92aa1e1
> *****************************************
|||Looks like your Sales column could be a VARCHAR/CHAR rather than a numeric
type. If so, it will make sense to change this in your table structure but
for now you can do:
SELECT *
FROM SaleVolume
ORDER BY CAST(sales AS INTEGER) DESC
David Portas
SQL Server MVP
for example i have 3 value
132
222
1122
now it order by
222
132
1122
but what i want is the biggest come first.
what should i do?
*****************************************
* This message was posted via http://www.sqlmonster.com
*
* Report spam or abuse by clicking the following URL:
* http://www.sqlmonster.com/Uwe/Abuse...18f948b92aa1e1
*****************************************
Is the datatype of the Sales coulmn char or varchar?
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com
"Gabe Wong via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:b1aa3babb0da40f38a18f948b92aa1e1@.SQLMonster.c om...
> select * from SaleVolumn order by Sales DESC
>
> for example i have 3 value
> 132
> 222
> 1122
> now it order by
> 222
> 132
> 1122
> but what i want is the biggest come first.
> what should i do?
> *****************************************
> * This message was posted via http://www.sqlmonster.com
> *
> * Report spam or abuse by clicking the following URL:
> *
http://www.sqlmonster.com/Uwe/Abuse...18f948b92aa1e1
> *****************************************
|||Looks like your Sales column could be a VARCHAR/CHAR rather than a numeric
type. If so, it will make sense to change this in your table structure but
for now you can do:
SELECT *
FROM SaleVolume
ORDER BY CAST(sales AS INTEGER) DESC
David Portas
SQL Server MVP
Order By in Biggest Value
select * from SaleVolumn order by Sales DESC
for example i have 3 value
132
222
1122
now it order by
222
132
1122
but what i want is the biggest come first.
what should i do?
*****************************************
* This message was posted via http://www.sqlmonster.com
*
* Report spam or abuse by clicking the following URL:
* http://www.sqlmonster.com/Uwe/Abuse.aspx?aid=b1aa3babb0da40f38a18f948b92aa1e1
*****************************************Is the datatype of the Sales coulmn char or varchar?
--
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com
"Gabe Wong via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:b1aa3babb0da40f38a18f948b92aa1e1@.SQLMonster.com...
> select * from SaleVolumn order by Sales DESC
>
> for example i have 3 value
> 132
> 222
> 1122
> now it order by
> 222
> 132
> 1122
> but what i want is the biggest come first.
> what should i do?
> *****************************************
> * This message was posted via http://www.sqlmonster.com
> *
> * Report spam or abuse by clicking the following URL:
> *
http://www.sqlmonster.com/Uwe/Abuse.aspx?aid=b1aa3babb0da40f38a18f948b92aa1e1
> *****************************************|||Looks like your Sales column could be a VARCHAR/CHAR rather than a numeric
type. If so, it will make sense to change this in your table structure but
for now you can do:
SELECT *
FROM SaleVolume
ORDER BY CAST(sales AS INTEGER) DESC
--
David Portas
SQL Server MVP
--
for example i have 3 value
132
222
1122
now it order by
222
132
1122
but what i want is the biggest come first.
what should i do?
*****************************************
* This message was posted via http://www.sqlmonster.com
*
* Report spam or abuse by clicking the following URL:
* http://www.sqlmonster.com/Uwe/Abuse.aspx?aid=b1aa3babb0da40f38a18f948b92aa1e1
*****************************************Is the datatype of the Sales coulmn char or varchar?
--
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com
"Gabe Wong via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:b1aa3babb0da40f38a18f948b92aa1e1@.SQLMonster.com...
> select * from SaleVolumn order by Sales DESC
>
> for example i have 3 value
> 132
> 222
> 1122
> now it order by
> 222
> 132
> 1122
> but what i want is the biggest come first.
> what should i do?
> *****************************************
> * This message was posted via http://www.sqlmonster.com
> *
> * Report spam or abuse by clicking the following URL:
> *
http://www.sqlmonster.com/Uwe/Abuse.aspx?aid=b1aa3babb0da40f38a18f948b92aa1e1
> *****************************************|||Looks like your Sales column could be a VARCHAR/CHAR rather than a numeric
type. If so, it will make sense to change this in your table structure but
for now you can do:
SELECT *
FROM SaleVolume
ORDER BY CAST(sales AS INTEGER) DESC
--
David Portas
SQL Server MVP
--
Wednesday, March 21, 2012
Order By
Is there a way to order data how you want besides Ascending or Descending? Example: I have M-F I need to sort in order of Monday-Friday.
Hi,
you could split up the queries to execute one for Monday, Tuesday... Friday. Then you can process the result sets in the order you want.
Otherwise I would store ordinals in the database like Monday = 0, Tuesday = 1 and so on.
--
SvenC
Hi,
instead of using one SqlCommand with an order by clause you could set up one SqlCommand which selects only rows where Day = Monday, a second SqlCommand which selects Day = Tuesday and so on. So you end up with one DataSet or DataTable per day.
Otherwise you would have to modify the table to change how your day is represented. Change it from varchar to int, and store 0 instead of 'Monday' and 1 instead of 'Tuesday', so the numbers sort like you want the days to sort.
Does that help you?
--
SvenC
Subscribe to:
Posts (Atom)