2009-05-14 26 views
0

Cette requête me donne l'erreur: Msg 156, niveau 15, état 1, ligne 10 Syntaxe incorrecte près du mot-clé «où».Comment puis-je évaluer cette requête?

declare @date1 datetime,@date2 datetime , @COUNT INT , @countgap int, @order int 
seLECT @date1='2009-05-11' , @date2 = '2009-05-12' 
seLECT @countgap = 30 , @COUNT = 0, @order=23 

select VisitingCount from (
select count(page) as VisitingCount, 
    (datepart(hour,Date)*60+datepart(minute,Date))/@countgap as OrderNumber 
    from scr_SecuristLog 
    where Date between @date1 and @date2 
    GROUP BY (datepart(hour,Date)*60+datepart(minute,Date))/@countgap) where [email protected]
+0

Je ne comprends pas Éditer du code dans stackoverflow? – Penguen

Répondre

3

Pherhaps:

GROUP BY (datepart(hour,Date)*60+datepart(minute,Date))/@countgap) 
HAVING [email protected] 

ou:

where (Date between @date1 and @date2) AND [email protected] 
GROUP BY (datepart(hour,Date)*60+datepart(minute,Date))/@countgap) 
2

Vous devez donner à votre table dérivée un nom par exemple DT1. Ici j'ai reformaté le texte SQL à mon goût personnel :) pour le rendre plus facile à lire:

select DT1.VisitingCount 
    from (
     select count(page) as VisitingCount, 
       (datepart(hour,Date)*60+datepart(minute,Date))/@countgap 
        as OrderNumber 
      from scr_SecuristLog 
     where Date between @date1 and @date2 
     GROUP 
      BY (datepart(hour,Date)*60+datepart(minute,Date))/@countgap 
     ) AS DT1 
where [email protected] 
Questions connexes