在ASP Classic和Show Results中运行MS SQL查询

时间:2013-06-28 22:51:56

标签: sql sql-server asp-classic vbscript

我想知道如何在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 然后:虽然不是objSchDeductions.EOF而只是循环所有它直到没有更多但由于某种原因它不起作用。

请帮助,谢谢...

1 个答案:

答案 0 :(得分: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)

请参阅:How do I run a parameterized SQL query in classic ASP? And is it secure?

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