Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 November 7th, 2007, 07:04 AM
Authorized User
 
Join Date: Jan 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Query Snapshot of Data in %

Below is sample data from a table, that I have been asked to analyze

VisitId OfficerId ActivityId MethodId RoleId
1, 1, KeyStage3, Visit, Consultant,
2, 2, KeyStage4, Email, SIP
3, 3, KeyStage4, Email, Consultant
4, 1, KeyStage3, Visit, Consultant
5, 1, Interview, Visit, General Inspector
6, 2, KeyStage4, Telephone, SIP
7, 4, KeyStage3, Email, General Inspector
8, 1, KeyStage3, Other, Consultant

The purpose of this table is that it records the visits of officers to sites where they do inspections.
What I have been asked to do is to create a report giving me a return like below where I can group an officers visits and then view the percentages for the selected fields.

So
Activity Method Role
----------------------------------------------------------------------------------------------------------
OfficerId Keystage3 KeyStage4 Visit Email Consultant SIP
-----------------------------------------------------------------------------------------------------------
1, 25%, 25%, 10%, 50%, 25%, 75%,
2, 5%, 10%, 5%, 10%, 33%, 25%,
3, 10%, 5%, 33%, 10%, 10%, 10%,


Now I can achieve the following result

OfficerId ActivityId Percentage CountOfficerVisits
1, 1, 25%, 3
1, 2, 25%, 3
1, 3, 50%, 3
2, 1, 50%, 2
2, 2, 50%, 2
3, 4, 100%, 2

But then I add the MethodId field it obviously compares activity & method fields expanding the recordset, returning not six rows perhaps 10 instead.

What is the best way to achieve my goal. Any advice much appreciated.

 
Old November 7th, 2007, 12:59 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Not sure if I can really be of any help. Can you post the query that you use to get your results? That's probably a good place to start. One thing I noticed is that your percentages don't equal 100%. Alsok, your ActivityID in the first set of results is "KeyStage3", etc. but in the second set of results ActivityID is an integer. Is that just an error when posing your question?

 
Old November 7th, 2007, 03:18 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Already asked and answered here
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=92216


 
Old November 7th, 2007, 06:37 PM
Authorized User
 
Join Date: Jan 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As some wise man once said, many hands make light work

 
Old November 8th, 2007, 04:41 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You are also blocking help to other people that may be in greater need, than you becuse you get double help...







Similar Threads
Thread Thread Starter Forum Replies Last Post
Snapshot doesn't work roy_mm Reporting Services 0 July 22nd, 2008 08:44 AM
Help Creating Snapshot Query eusanpe Access VBA 3 July 12th, 2007 01:33 PM
Snapshot recordset returning only 1 record probitaille Access VBA 2 September 6th, 2006 06:16 PM
Take Snapshot into JPG file r_s_pathak Visual C++ 0 January 27th, 2005 03:20 AM
how to open Snapshot file learnvb Access VBA 2 January 12th, 2004 04:52 PM





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