Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Replace batch update on daily basis
Message
From
15/02/2009 17:24:56
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Application:
Web
Miscellaneous
Thread ID:
01381959
Message ID:
01381975
Views:
20
>Sorry I cannot help you because I do not understand what your query does.

I have a Hit table. That is every hit a user does on the site. So, I can have, for example, 100,000 records to one million per day. Using that table, I need to process daily statistics. I have another table named StatisticDaily for that purpose. This table contains one record per day. In each day, I collect various statistics. So, each record has a date which represents the day. I have a robot which executes at interval and one of its tasks it to update those stats.

So, if I have 132,111 hits for today, this might represent a total number of 156 logins, a total number of 142 unique logins and a total number of 189 users who did a hit on the site. The reason 189 is greater than 142 is because some users didn't have to login or didn't want to because the browser remained opened for several days. It is that number that I need to collect.

So, when my robot runs, it executes the following command to update the actual daily record to collect the data for the number of users:
DECLARE @AddDate DateTime
DECLARE @AddDate2 DateTime

SET @AddDate='2009-02-14 00:00:00'
SET @AddDate2='2009-02-14 23:59:59'

SELECT COUNT(*) FROM Hit WHERE Hit.AddDate>=@AddDate AND Hit.AddDate<=@AddDate2 GROUP BY AddUser
Then, from that command, I can execute an update on StatisticsDaily to update the User field with the count of the SQL represented above. So, if my data provider is named loDataProvider, for the execution of the above command, I can do something like this where loDataProvider.nCount is the number of records that was retrieved:
DECLARE @User Integer
DECLARE @Numero Integer

SET @User=loDataProvider.nCount
SET @Numero=234334

UPDATE StatisticDaily SET [User]=@User WHERE Numero=@Numero
This is good and will be for all upcoming executions of this command for as long as we move forward. But, all previous records have 0 presently on the Statistic table. So, basically, I would like to execute this update by script, the update that will adjust all previous records, as I do not want to build an application to loop thru all records from the StatisticDaily table and execute the command for each day. So, basically, I would like to do all that in one update I can then give to the database administrator so he will execute it in SSMS.

So, basically, it would go like this:
UPDATE StatisticsDaily SET [User]=CountOfDailyFoundInHitPerUser
 FROM Hit WHERE StatisticDaily.Date=Hit.Date AND Hit.AddUser>0 GROUP BY Hit.AddUser
Of course, that command cannot be executed as is. I am just trying to explain what I need to achieve. There are a few obstacles here. First, Statistic.Date is a Datetime field. So, it is something like 2009-02-14 00:00:00, for a daily representation. And, I need to obtain a count as per a group in hit on a daily basis, but a group per Hit.AddUser where Hit.AddUser would be greater than 0.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform