insert statement problem
Hi all,
I'm trying to calculate the data from one table and insert the results into another table. The queries are the following:
1. select top 5 userId, count(photoId) numOfPhoto from photo group by userId order by count(photoId) desc
2. select top 5 userId, count(photoId) numOfPhoto from photo where datesubmitted > DATEADD(dd,-30,DATEADD(dd, DATEDIFF(dd,0,getdate()), 0)) and datesubmitted < DATEADD(dd,-8,DATEADD(dd, DATEDIFF(dd,0,getdate()), 0))group by userId order by count(photoId) desc
3. select top 5 userId, count(photoId) numOfPhoto from photo where datesubmitted > DATEADD(dd,-7,DATEADD(dd, DATEDIFF(dd,0,getdate()), 0)) and datesubmitted < DATEADD(dd, DATEDIFF(dd,0,getdate()), 0) group by userId order by count(photoId) desc
The another table's structure is the following:
id, overall, overallNum, monthly, monthlyNum, weekly, weeklyNum
the first query's result will go to overall and overallNum, the second query's result will go to monthly and monthlyNum, the third query's result will go to weekly and weeklyNum
Sorry about my bad English. Is this possible, shall I use something like table valued function?
Thanks a lot,
Jason

