Click here to Skip to main content
15,918,211 members
Home / Discussions / Database
   

Database

 
GeneralRe: Simple Dataset Question... Pin
Bill Dean20-Feb-04 5:07
Bill Dean20-Feb-04 5:07 
GeneralRe: Simple Dataset Question... Pin
Verdant12322-Feb-04 3:01
Verdant12322-Feb-04 3:01 
GeneralParameters of PutElement() Pin
girl_lash18-Feb-04 16:26
girl_lash18-Feb-04 16:26 
Generalassociating child to parent Pin
ylaine18-Feb-04 16:05
ylaine18-Feb-04 16:05 
GeneralMissing VNSAPI32.dll Pin
Bakos, Zsolt18-Feb-04 9:50
Bakos, Zsolt18-Feb-04 9:50 
GeneralRe: Missing VNSAPI32.dll Pin
Mike Dimmick19-Feb-04 6:12
Mike Dimmick19-Feb-04 6:12 
GeneralTrouble with query Pin
gamerPotatoe18-Feb-04 1:38
gamerPotatoe18-Feb-04 1:38 
GeneralRe: Trouble with query Pin
Mike Dimmick18-Feb-04 2:36
Mike Dimmick18-Feb-04 2:36 
Ah, the old cross-tab problem. Quite tricky in SQL Server 2000.

One technique that I've had success with is to define a temporary table containing all the months of interest:
DECLARE @months TABLE
(
   MonthNum int NOT NULL
)
 
INSERT INTO @months
SELECT 1 UNION ALL
SELECT 2 UNION ALL
SELECT 3 UNION ALL
SELECT 4 UNION ALL
SELECT 5 UNION ALL
SELECT 6 UNION ALL
SELECT 7 UNION ALL
SELECT 8 UNION ALL
SELECT 9 UNION ALL
SELECT 10 UNION ALL
SELECT 11 UNION ALL
SELECT 12
You also need a table for categories:
DECLARE @classes TABLE
(
   ClassName varchar(5) NOT NULL
)
 
INSERT INTO @classes
SELECT 'First' UNION ALL
SELECT 'Third'
You can then join these tables onto your data to get an output that looks something like this:
 Class | Month | Reservations
-----------------------------
 First |  Jan  |   130
 First |  Feb  |   500
 First |  Mar  |   320
 First |  Apr  |   112
  ...
 First |  Dec  | count
 Third |  Jan  | count
 Third |  Feb  | count
  ...
 Third |  Dec  | count
You'll then need to juggle the results into the appropriate output format in the client application.

To give you a bit of a start, you might count the number of tickets issued in each month like so:
SELECT
  ClassName AS Class,
  DATENAME(month, DATEADD(m, MonthNum - 1, '20040101')) AS Month,
  COUNT(TKTNO) AS [Count]
FROM
  Tickets_Purchased TP
RIGHT JOIN
  (
     SELECT ClassName, MonthNum
     FROM @classes CROSS JOIN @months
  ) Crit
   ON TP.CLASS = Crit.ClassName AND MONTH(TP.DATEPURCHASE) = Crit.MonthNum
GROUP BY
  ClassName, MonthNum
ORDER BY
  ClassName, MonthNum
I'm sure you can work out the rest from here.
GeneralRe: Trouble with query Pin
Edbert P19-Feb-04 13:28
Edbert P19-Feb-04 13:28 
GeneralHelp with big stored procedure Pin
Verdant12317-Feb-04 20:25
Verdant12317-Feb-04 20:25 
GeneralRe: Help with big stored procedure Pin
Not Active18-Feb-04 1:06
mentorNot Active18-Feb-04 1:06 
GeneralRe: Help with big stored procedure Pin
Verdant12318-Feb-04 1:58
Verdant12318-Feb-04 1:58 
Generalgetting columns data rowwise Pin
percyvimal17-Feb-04 16:59
percyvimal17-Feb-04 16:59 
GeneralRe: getting columns data rowwise Pin
Mazdak17-Feb-04 18:23
Mazdak17-Feb-04 18:23 
GeneralCreating SQL tables from XML schema Pin
blurp17-Feb-04 13:04
blurp17-Feb-04 13:04 
GeneralShowing Multiple tables in Datagrid Pin
Qamarwis17-Feb-04 9:56
Qamarwis17-Feb-04 9:56 
GeneralRe: uMultiple tables in Datagrid Pin
Mazdak17-Feb-04 10:01
Mazdak17-Feb-04 10:01 
QuestionWhat is ??? The Problem Pin
jinbabaj17-Feb-04 3:56
jinbabaj17-Feb-04 3:56 
AnswerRe: What is ??? The Problem Pin
Edbert P17-Feb-04 17:19
Edbert P17-Feb-04 17:19 
GeneralRetrieving a list of tables (ADO) Pin
pl0p16-Feb-04 17:28
pl0p16-Feb-04 17:28 
GeneralRe: Retrieving a list of tables (ADO) Pin
Mazdak16-Feb-04 17:47
Mazdak16-Feb-04 17:47 
GeneralRe: Retrieving a list of tables (ADO) Pin
-Dr_X-20-Feb-04 11:16
-Dr_X-20-Feb-04 11:16 
GeneralAccess Pin
Anonymous16-Feb-04 16:05
Anonymous16-Feb-04 16:05 
GeneralRe: Access Pin
-Dr_X-20-Feb-04 11:23
-Dr_X-20-Feb-04 11:23 
GeneralSelect MID?? instead of TOP Pin
krisp16-Feb-04 11:26
krisp16-Feb-04 11:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.