Click to See Complete Forum and Search --> : crosstab query in SQL


nganb
10-03-2006, 11:23 AM
I have a crosstab query in Access XP that I want to be used in SQL and my ASP page. The query is the following:

TRANSFORM Count(tblStandOrder.SOID) AS CountOfSOID
SELECT Hour([RequestPUTime]) AS RequestHour, Count(tblStandOrder.SOID) AS [Total Of SOID]
FROM tblStandOrder
GROUP BY Hour([RequestPUTime])
PIVOT tblStandOrder.RequestDay;

I have a table of orders which has the SOID (PK), PUTime (hh:mm), and RequestDay (Sun-Sat). I want a crosstab results on my asp page that will count up all the orders for each day and hour (if PUTime is 12:30pm, that record would be part of the 12 hour count).

So I want it to look like this:

Hr Sunday Monday Tuesday Wednesday Thursday Friday Saturday
00 5 10 1 357 56 56 56
01 34 356 46 99 99 8 90
....
23 56 23 34 342 435 23 13

How to go about writing the SQL query (View) and translating it onto an asp page?