Computing.Net > Forums > Database > Need Urgent Help in MS SQL Express

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Need Urgent Help in MS SQL Express

Reply to Message Icon

Name: ivan603
Date: September 8, 2008 at 01:25:56 Pacific
OS: WindowsXP
CPU/Ram: 512MB
Comment:

Hi all,
I need a help in MS SQL Express query. I have a table named "tblTotalCust" and the fields are:
[Date] date, [ServedTime] date, [TotalCustomer] int.

Example data:
[Date] [ServedTime] [TotalCustomer]
8/9/2008 12:00:00AM 8/9/2008 9:23:00AM 12
8/9/2008 12:00:00AM 8/9/2008 9:27:00 AM 7
8/9/2008 12:00:00AM 8/9/2008 9:37:00AM 9
8/9/2008 12:00:00AM 8/9/2008 10:45:00AM 25
8/9/2008 12:00:00AM 8/9/2008 10:57:00AM 11
8/9/2008 12:00:00AM 8/9/2008 11:32:00AM 6

In MS Access, my query is :

SELECT Date, TimeSerial(0, ((HOUR(ServedTime) * 60 + MINUTE(ServedTime))\30)*30,0) AS TimeOfDay, SUM(TotalCustomer) AS TotalCustomer GROUP BY Date, TimeSerial(0,
((HOUR(ServedTime) * 60 + MINUTE(ServedTime))\30)*30,0)

This will produce a sum TotalCustomer in each 30 minute of ServedTime as below:
[Date] [TimeOfDay] [TotalCustomer]
8/9/2008 12:00:00AM 8/9/2008 9:00:00AM 19
8/9/2008 12:00:00AM 8/9/2008 9:30:00AM 9
8/9/2008 12:00:00AM 8/9/2008 10:30:00AM 36
8/9/2008 12:00:00AM 8/9/2008 11:30:00AM 6

But how do i write this query in MS SQL Express? Please help. Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: chao
Date: November 13, 2008 at 00:29:44 Pacific
Reply:

(edit: i'd originally written the query for a whole different table with different fields. had to change a field name to match.)

I don't remember much about Access, especially what TimeSerial does and whether/how it's used in MSSQL, so i did a MSSQL query from scratch. Basically, it subtracts (minutes % 30) minutes and (seconds) seconds from TimeServed to get the half hour intervals.

SELECT [Date],
DATEADD(SECOND, -((DATEPART(MINUTE, TimeServed) % 30) * 60 + DATEPART(SECOND, TimeServed)), TimeServed) TimeOfDay,
SUM(TotalCustomer) TotalCustomer
FROM tblTotalCust
GROUP BY [Date], DATEADD(SECOND, -((DATEPART(MINUTE, TimeServed) % 30) * 60 + DATEPART(SECOND, TimeServed)), TimeServed)


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Database Forum Home


Sponsored links

Ads by Google


Results for: Need Urgent Help in MS SQL Express

How to create a function in MS Acce www.computing.net/answers/dbase/how-to-create-a-function-in-ms-acce/328.html

cant access ms sql server www.computing.net/answers/dbase/cant-access-ms-sql-server/119.html

select statement help! www.computing.net/answers/dbase/select-statement-help/283.html