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 2000 Forums
 SQL Server Development (2000)
 combining dates

Author  Topic 

stsql
Starting Member

19 Posts

Posted - 2006-04-14 : 07:42:56
Hi all,

I would like to merge fields within this table:

create table eventViews
(
viewID int,
eventID varchar,
active varchar,
DateAdded datetime,
views int,
clientviews int
)

I would like to combine all fields where the dateadded is the same day and the eventid is the same. In doing so I would like to total all views that are in the fields that are to be merged and add those to the new view row.

Any ideas how to approach this?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-14 : 07:46:49
Do you need something like this?
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx?Pending=true

Otherwise post some sample data and the result you want

Madhivanan

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

stsql
Starting Member

19 Posts

Posted - 2006-04-14 : 08:03:43
Hi madhivanan,

I don't think thats what I'm looking for, but I'm no expert.

Here's some sample data:

viewID | eventID | active | DateAdded | views | clientviews |
1 | 1 | 1 | 17/01/2006| 1 | 0 |
2 | 1 | 1 | 18/01/2006| 3 | 0 |
3 | 2 | 1 | 19/01/2006| 1 | 0 |
4 | 1 | 1 | 18/01/2006| 2 | 0 |

Would give:

viewID | eventID | active | DateAdded | views | clientviews |
1 | 1 | 1 | 17/01/2006| 1 | 0 |
2 | 1 | 1 | 18/01/2006| 5 | 0 |
3 | 2 | 1 | 19/01/2006| 1 | 0 |

NB. viewid is just the primary key and values to me aren't important.


Thanks,

R
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-04-14 : 08:13:20
[code]select eventID, active, DateAdded, sum(views), sum(clientviews)
from eventViews
group by eventID, active, DateAdded[/code]



KH


Go to Top of Page

stsql
Starting Member

19 Posts

Posted - 2006-04-14 : 09:13:40
Thanks khtan.


Richard
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-17 : 02:27:52
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

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

- Advertisement -