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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Grouping by Date

Author  Topic 

shawnmolloy
Yak Posting Veteran

93 Posts

Posted - 2009-03-03 : 01:46:33
Hi.

I'm building this fairly complex query and need a little help.

I need the results to be grouped by the date. For example, I need to see all the "activity" for each day.

To make this easier, I took some screen shots.

This is what I'd like the result set to look like:


Here is the Schema:


When I built a query, it is looking up the data by the "UserID", which is desired, but I want to organize it by date.



So one thought I had was I could do a query per date, but that is obviously a lot of unnecessary overhead.

What technique would you recommend to query the data to look like this:


(Search by USER ID)

DateAdded (2009/2/20)
- Activity 1
- Activity 2
- Activity 3

Date Added (2009/2/21)
- Activity 1
- Activity 2
- Activity 3


I hope this makes sense! Thanks for your help guys.



Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-03-03 : 01:52:26
add the dateadded parameter in ur code , check that one in where condition
Go to Top of Page

shawnmolloy
Yak Posting Veteran

93 Posts

Posted - 2009-03-03 : 02:48:49
What? I'm afraid I don't understand your reply. You're saying just to add "WHERE DATE ADDED=@DATEADDED"?

How will that help me? I will have to run the stored proc for each date. This is exactly what I was saying I wanted to avoid......
Go to Top of Page

subhash chandra
Starting Member

40 Posts

Posted - 2009-03-03 : 03:21:42
I think your requirement can be fullfilled by the combination of code in T-SQL and any frontend language (or reporting tool). Date values from tables can simply returned using GROUP BY caluse then you will have to place it at specific location.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-03 : 09:41:09
I also agree to subhash. the format in which you want output can be easily obtained using sql reports by grouping on date value and then displaying item belonging to each.
Go to Top of Page

shawnmolloy
Yak Posting Veteran

93 Posts

Posted - 2009-03-04 : 12:05:20
I think you're right; but in my case, since the display is an asp.net web form, I should be looking towards data binding controls.

Thank you!
Go to Top of Page

Itamar
Starting Member

19 Posts

Posted - 2009-03-16 : 15:35:24
You can use a third party tool that will help you do the Grouping you wish, check this Query tool- http://nobhillsoft.com/MarieAlix_detail.aspx, its good for different kind of databases.

(Off topic- we are looking for people who will want to check our Beta version, and have the software for free..)

http://www.nobhillsoft.com
Database tools, SQL,MySQL...
Go to Top of Page
   

- Advertisement -