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 February 8th, 2005, 12:38 PM
Authorized User
 
Join Date: Oct 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default summarize data

Hi,

I have a table that contains the following fields
StudentId , NoOfChildren, Over18 stat
 1 2 null 0
 2 1 1 -1
 3 2 0 0
 4 3 1 0
studentid is an identity field.

What I need to do is calculate the number of children per household
(NoOfChildren -over18)+stat
and put them into columns such as the following:
1-3 4-5
  1 3

If in the table there is only one family with 1-3 household members it goes under 1-3, if there are 3 families with 4-5 household members it will go under column 4-5.
also if stat=0 then i need to add by 2 else add by one.

How can I accomplish that?

Thanks




 
Old February 8th, 2005, 01:15 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

something like this....little confused what exactly you want but

SELECT (NoOfChildren + CASE Over18
                        WHEN 1 Then -1
                        ELSE 0 END +
                       CASE Stat
                WHEN 0 THEN 2
                ELSE 1 END ) As TotalChildren
From TestC
 
Old February 9th, 2005, 04:54 AM
Authorized User
 
Join Date: Oct 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the help :)
I have another question.
The result that I get now is as follows:
TotalChildren
8
1
8
8
8
1
1
8
1
1
1
1
1
1
Now I need to count the TotalChildren. If for example there are five rows that the TotalChildren=8 i need to place 5 in a column called Five-Eight
IF there are 9 rows of TotalChildren =1
Then I need to place 9 under a column called Nine-Eleven.

The result can be displayed as follows:
CountTotalChildren Name
 5 Five-Eight
 6 Five-Eight
 9 Nine-Eleven

Thanks







Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in e-mail structure sending data from data tiawebchd General .NET 3 May 5th, 2008 08:07 AM
Data Binding - Editing GridView Row Data desk_star BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 7 December 30th, 2007 11:07 AM
Transfering data from csv file to data base g_vamsi_krish ASP.NET 1.0 and 1.1 Professional 2 May 16th, 2006 11:58 PM
Summarize Cross-Tabs mile_erg Crystal Reports 0 July 1st, 2005 01:15 AM





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