Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Replace batch update on daily basis
Message
 
 
À
15/02/2009 16:16:13
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Application:
Web
Divers
Thread ID:
01381959
Message ID:
01381963
Vues:
29
First, there's a problem with your code. SQL Server stores datetime values with millisecond portion and your select will miss records with time > '23:59:59.000'. I usualy do this way
SET @AddDate  = '2009-02-14 00:00:00'
SET @AddDate2 =  @AddDate + 1     -- +1 day
SELECT COUNT(*) AS CountHit FROM Hit WHERE Hit.AddDate >= @AddDate AND Hit.AddDate < @AddDate2 GROUP BY AddUser
Second, it's not clear what into you store into StatisticDaily.User table because your query returns # of hits per user not the # of unique users.

BTW, aren't you using SQL 2008?

>This is a command that I execute to update some statistics on a daily basis:
>
>
>DECLARE @AddDate DateTime
>DECLARE @AddDate2 DateTime
>
>SET @AddDate='2009-02-14 00:00:00'
>SET @AddDate2='2009-02-14 23:59:59'
>
>SELECT COUNT(*) AS CountHit FROM Hit WHERE Hit.AddDate>=@AddDate AND Hit.AddDate<=@AddDate2 GROUP BY AddUser
>
>
>So, in this example, I can gather the amount of unique users for today. Then, I save that into StatisticDaily.User. Among a set of fields already in place, that one has been added recently. So, basically, for all previous records, the values in the StatisticDaily.User is empty. I need to execute an update command that will update the StatisticDaily.User field for all previous records. So, what would be the syntax for an update command to achieve this task for all previous records?
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform