0

我想知道如何在 ASP Classic 中运行这个 MS SQL 查询并像在 MS SQL 中一样获得结果。

DECLARE @weeks int = 26

;WITH Person AS (
   SELECT
     datediff(ww, DATE_GIVEN, getdate())+1 AS Week,
     AVG(CHECK_AMOUNT) AS Person_Check_Amount
   FROM CHECKS
   WHERE PERSON_NO=11  AND DATE_GIVEN >= dateadd(ww, -@weeks, getdate())
   GROUP BY datediff(ww, DATE_GIVEN, getdate()) +1
)

, Company AS (
    SELECT week,
  AVG (COMPANY_Check_Amount) AS COMPANY_Check_Amount
    FROM (
       SELECT
         datediff(ww, DATE_GIVEN, getdate())+1 AS Week,
         SUM(CHECK_AMOUNT)/COUNT(DISTINCT PERSON_NO) AS COMPANY_Check_Amount
       FROM CHECKS
       WHERE PERSON_NO<>11  AND DATE_GIVEN >= dateadd(ww, -@weeks, getdate())
       GROUP BY datediff(ww, DATE_GIVEN, getdate())+1 
    ) t
  GROUP BY Week
)

SELECT c.week
 , isnull(Person_Check_Amount,0)  Person_Check_Amount
 , isnull(Company_Check_Amount,0) Company_Check_Amount
FROM Person p
FULL OUTER JOIN Company c ON c.week = p.week
ORDER BY Week DESC

然后我想循环这个并显示结果。

我认为它就像这样简单:dim strQuery =“ PUT ABOVE CODE HERE ”然后运行:objSchDeductions.Open strQuery 然后:while not objSchDeductions.EOF 并循环所有它直到没有更多但它不是出于某种原因工作。

请帮忙,谢谢...

4

1 回答 1

3

对于经典 ASP,您可能需要查看http://www.w3schools.com/asp/

ADODB.Command 对象相当于 SqlCommand。从那里开始,它基本上与 .NET 中的操作相同。

set cmd = Server.CreateOject("ADODB.Command")
cmd.CommandText = "select From Table where ID = @id")
set param = cmd.CreateParameter("@id", adInteger, adInput,0,0)

请参阅:如何在经典 ASP 中运行参数化 SQL 查询?它安全吗?

http://support.microsoft.com/kb/200190

于 2013-06-29T08:22:32.203 回答