Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 12th, 2005, 04:38 PM
Registered User
 
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL Calculation

Sorry for the cross posting but I am getting desperate now.

I have a table with 11 fields as follow:

Column Name Data Type Length

strEmployeeID varchar 9
strReportTime_Mon varchar 12
strReportTime_Tue varchar 12
strReportTime_Wed varchar 12
strReportTime_Thu varchar 12
strReportTime_Fri varchar 12
strCommute_Mon varchar 2
strCommute_Tue varchar 2
strCommute_Wed varchar 2
strCommute_Thu varchar 2
strCommute_Fri varchar 2

All the strReportTime are in actually time like 06:00 AM or 06:30 AM or 06:00 PM, etc etc.

Possible data for StrCommute are A through Z and AA, BB and CC. Here is a sample data

091100867 08:00 AM 08:00 AM 08:00 AM 08:00 AM 07:00 AM A A A A A
091098216 08:00 AM 08:00 AM 08:00 AM 08:00 AM 08:00 AM Q Q Q Q Q
091456272 07:00 AM 07:30 AM 07:00 AM 07:00 AM 08:00 AM A A A A A
091748216 09:00 AM 09:00 AM 09:00 AM 09:00 AM 09:00 AM S S S S S
090054234 08:00 AM 08:00 AM 08:00 AM 08:00 AM 08:00 AM A A A A A
090027502 02:30 PM 02:30 PM 02:30 PM 02:30 PM <Null> B B B B CC
091131059 15:00 PM 08:00 AM 07:00 AM 07:00 AM 07:00 AM A A A A CC

Now goal is to find the sum of count of all the commute methods for each day and total for week as follows:

Mode Mon Tues Wed Thu Fri Total

A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
AA
BB
CC

Any help would be appreciated.

Thanks.

Habib.
 
Old December 13th, 2005, 06:28 AM
Registered User
 
Join Date: Dec 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi.

For Mode A and column Mon you can do this:

select count(strCommute_Mon) from <table_name>
where strCommute_Mon = 'A'

You can insert result data into a table and do a while do fill all table cells.

This is one option.
 
Old January 6th, 2006, 06:23 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Anantsharma Send a message via Yahoo to Anantsharma
Default

See "Rotating Table in Sql Server " Topic in BOL or MSDN. There is an example like this one.

B. Anant





Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculation using if...then...else statement oliver ASP.NET 1.0 and 1.1 Basics 2 March 7th, 2007 07:29 PM
Complex calculation. rupen Classic ASP Professional 0 May 18th, 2006 04:37 AM
Calculation dillemma.... cuzintone SQL Language 0 April 7th, 2005 03:59 PM
Calculation Grantm Access 3 February 16th, 2004 10:14 AM
Skewness calculation in SQL statement akmhasan Oracle 0 July 13th, 2003 04:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.