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)
 Group by

Author  Topic 

mahimam_2004
Starting Member

40 Posts

Posted - 2007-03-12 : 17:39:13
Hi ,
I have the following query,
Select * from DB2006.dbo.rptfunChronicity('Dec 15 2005 12:00AM','Jan 31 2006 12:00AM',97,010)
Union
Select * from DB2007.dbo.rptfunChronicity('Dec 15 2005 12:00AM','Jan 31 2006 12:00AM',97,010)
Now the query returning the results like this:
Number ID Desc
9 3 Chronic
13 2 Acute-on-chronic
15 2 Acute-on-chronic
24 3 Chronic
1793 1 Acute
3456 1 Acute

From the above result I need to get
Number ID Desc
33 3 Chronic
28 2 Acute-on-chronic
5249 1 Acute
Grouped by ID value.
Thanks in advance


LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2007-03-12 : 18:03:12
something like

select sum(number), id, desc
from(
Select * from DB2006.dbo.rptfunChronicity('Dec 15 2005 12:00AM','Jan 31 2006 12:00AM',97,010)
Union
Select * from DB2007.dbo.rptfunChronicity('Dec 15 2005 12:00AM','Jan 31 2006 12:00AM',97,010)
) as x
group by id, desc


May I suggest you also get rid of your multiple databases and start spraying a year column around.
Go to Top of Page
   

- Advertisement -