Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server / October 2007

Tip: Looking for answers? Try searching our database.

Getting a Code to Compute Totals

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JOHN HARRIS - 31 Oct 2007 15:39 GMT
The code listed below is being used from inside Crystal Reports to build a
cross tab report showing the total number of clients by level (1,2,3,E, or
P) and Type (I or P). What I would like to do is add some compute statements
(or something) to the end of this query that would show this total rollup
without having to use Crystal.

So for example, the query would show first the site name (i.e. CENTRAL), the
WORKERID assigned to each site (as many as 6 in some cases) then the total,
by workerId of how many I clients (Infants) and how many P clients
(Prenatal) by Assigned to each level (1,2,3,E,P).

This works fine inside Crystal, but in order to place it on the database
system I have to use a SQL code for the Site Managers to run. I have tried a
few COMPUTE statements but cannot get them to work as I need them to.

Any ideas or suggestions?

SELECT     Account_Sites.Name, Account_Membership.WorkerID, Clients.SSNum,
Clients.First_Name + ' ' + Clients.Last_Name AS CLIENT,
Clients.clientType, Clients.clientLevel
FROM         Account_Membership INNER JOIN
                     Account_Sites ON Account_Membership.Site_ID =
Account_Sites.ID INNER JOIN
                     Clients ON Account_Membership.ID =
Clients.Membership_ID

Signature

JOHN C. HARRIS, MPA, MBA
JCZ CONSULTING OF TAMPA BAY
813-361-8826
JCZ@TAMPABAY.RR.COM

John Bell - 31 Oct 2007 19:39 GMT
Hi John

There are CUBE and ROLLUP commands in SQL Server see
http://msdn2.microsoft.com/en-us/library/Aa213210(SQL.80).aspx You may need
to use a derived table with a where clause to eliminate the rows you don't
want, alternatively you can UNION multiple statements and return an extra
value that will enable you to differentiate detail from totals for example
http://tinyurl.com/3cc293

John

> The code listed below is being used from inside Crystal Reports to build a
> cross tab report showing the total number of clients by level (1,2,3,E, or
[quoted text clipped - 21 lines]
>                       Clients ON Account_Membership.ID =
> Clients.Membership_ID
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.