Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to use sorting in group by method

Author  Topic 

pentahari
Starting Member

26 Posts

Posted - 2008-08-26 : 03:56:01
how to use sorting in group by.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-26 : 04:00:14
sorting is done by using order by
Go to Top of Page

pentahari
Starting Member

26 Posts

Posted - 2008-08-26 : 04:04:06
quote:
Originally posted by visakh16

sorting is done by using order by


My query is:
select dateadd(month, datediff(month, 0, voucher.vou_date), 0) as a  from voucher where vou_date>='6/26/2007' and vou_date<'8/27/2008' group by dateadd(month, datediff(month, 0, voucher.vou_date), 0)


The above query's result is not sorting.

Thanks Advance,
PentaHari

Go to Top of Page

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-08-26 : 04:12:52
quote:
Originally posted by pentahari

quote:
Originally posted by visakh16

sorting is done by using order by


My query is:
select dateadd(month, datediff(month, 0, voucher.vou_date), 0) as a  from voucher where vou_date>='6/26/2007' and vou_date<'8/27/2008' group by dateadd(month, datediff(month, 0, voucher.vou_date), 0) order by dateadd(month, datediff(month, 0, voucher.vou_date), 0)



The above query's result is not sorting.

Thanks Advance,
PentaHari





Where is order by as suggested by Visakh.
Add order by to your query.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-26 : 04:13:19
How do you expect it to sort when you've not specified any specific order for sorting by using order by?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-26 : 04:16:05
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-26 : 04:16:36
select dateadd(month, datediff(month, 0, voucher.vou_date), 0) as a from voucher where vou_date>='6/26/2007' and vou_date<'8/27/2008' group by dateadd(month, datediff(month, 0, voucher.vou_date), 0) order by a


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -