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.
| Author |
Topic |
|
shyamprasad76
Starting Member
38 Posts |
Posted - 2002-01-02 : 11:34:36
|
| Hi,I have a table that has two columns:MonthPar varchar, DateMem Datetime. Below is the sample data in the table:[MonthPar] [DateMem]DEC1998 1998-12-01 00:00:00.000DEC1998 1998-12-02 00:00:00.000JAN1999 1999-01-08 00:00:00.000JAN1999 1999-01-09 00:00:00.000FEB1999 1999-01-25 00:00:00.000FEB1999 1999-01-26 00:00:00.000---- ------- ------ ------ --------- ------- ------ ------ -----DEC1999 1999-12-01 00:00:00.000DEC1999 1999-12-02 00:00:00.000JAN2000 2000-01-08 00:00:00.000JAN2000 2000-01-09 00:00:00.000I want to select distinct MonthPar from the table. The thing is i have to Order by DateMem. This is beacuse i want to show like this to the user:DEC1998, then JAN1999, FEB1999,......,DEC1999,JAN2000 etc.Right now it shows DEC1998, DEC1999, JAN1999,JAN2000, like that.The problem is when i SELECT [MonthPar] GROUP BY [MonthPar], it does not allow me to ORDER BY [DATEMEM] as it is not in the GROUP BY OR SELECT list.Please help me in the transact sql. I would like this to write in a single query.Thanks,Prasad. |
|
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2002-01-02 : 12:48:01
|
| GROUP BY [MonthPar] ORDER BY MIN([DateMem])should work fine, though it does seem a bit odd to store both the date and the month of that date as columns in the table. |
 |
|
|
shyamprasad76
Starting Member
38 Posts |
Posted - 2002-01-02 : 13:03:56
|
Hi Arnold,I know having both the pieces of information in the same table is pretty odd. I am doing the conversion of the access application to SQL server. so, not really have to change the app code.Any way, your reply helped. I messed up the whole thing by using both DISTINCT and GROUP BY in the select.Thanks,Prasad.quote: GROUP BY [MonthPar] ORDER BY MIN([DateMem])should work fine, though it does seem a bit odd to store both the date and the month of that date as columns in the table.
|
 |
|
|
|
|
|
|
|