473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Specifying date headings in Crosstab Query

I'm currently running a crosstab query that displays the total amounts of Appointments that each Consultant.

Currently it is Consultant ID as the Rows, and Appointment Date as the top headings, grouped by Date (rather than month etc.)

But it is giving me a random order of dates going up numerically by day and no more.

Is there any way of giving an order to the Date columns or specifying that is should be for the next 7 days etc? here is the SQL Script
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Count(Appointment.[Appointment Number]) AS [CountOfAppointment Number]
  2. SELECT Appointment.[Consultant ID], Count(Appointment.[Appointment Number]) AS [Total Of Appointment Number]
  3. FROM Appointment
  4. WHERE (((Format([Appointment Date],"Short Date")) Between Date() And (Date()+7)))
  5. GROUP BY Appointment.[Consultant ID]
  6. PIVOT Format([Appointment Date],"Short Date");
  7.  
Jan 12 '08 #1
4 2291
puppydogbuddy
1,923 Expert 1GB
I'm currently running a crosstab query that displays the total amounts of Appointments that each Consultant.

Currently it is Consultant ID as the Rows, and Appointment Date as the top headings, grouped by Date (rather than month etc.)

But it is giving me a random order of dates going up numerically by day and no more.

Is there any way of giving an order to the Date columns or specifying that is should be for the next 7 days etc? here is the SQL Script
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Count(Appointment.[Appointment Number]) AS [CountOfAppointment Number]
  2. SELECT Appointment.[Consultant ID], Count(Appointment.[Appointment Number]) AS [Total Of Appointment Number]
  3. FROM Appointment
  4. WHERE (((Format([Appointment Date],"Short Date")) Between Date() And (Date()+7)))
  5. GROUP BY Appointment.[Consultant ID]
  6. PIVOT Format([Appointment Date],"Short Date");
  7.  

I don't know if this will work, but it is worth a try. I'm using DateDiff to sequence the Pivot Columns. To display the sequence and the date on different lines, increase the number of spaces between the sequencer and the date in the Pivot column until the desired effect is achieved.
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Count(Appointment.[Appointment Number]) AS [CountOfAppointment Number]
  2. SELECT Appointment.[Consultant ID], Count(Appointment.[Appointment Number]) AS [Total Of Appointment Number]
  3. FROM Appointment
  4. WHERE (((Format([Appointment Date],"Short Date")) BETWEEN Date() AND (Date()+7)))
  5. GROUP BY Appointment.[Consultant ID]
  6. PIVOT DateDiff("d",[Date(), [Appointment Date]) & "   " & Format([Appointment Date],"Short Date");
Jan 12 '08 #2
I appreciate the help puppy, and I gave your coding a shot, unfortunately it's returning similiar values, and additionally the difference is displaying as a number in the column headings. Aka " -333 17/7/2007". I've tried my hand at rearranging a few things here and there but still getting the same results.

Any more suggestions that I could try out? any feedback is greatly appreciated
Jan 13 '08 #3
puppydogbuddy
1,923 Expert 1GB
I appreciate the help puppy, and I gave your coding a shot, unfortunately it's returning similiar values, and additionally the difference is displaying as a number in the column headings. Aka " -333 17/7/2007". I've tried my hand at rearranging a few things here and there but still getting the same results.

Any more suggestions that I could try out? any feedback is greatly appreciated

I just realized that the Format function outputs text strings and that is why your date is not ordering properly. All you need to do is pivot on the appointment date (unformatted as shown below) and it should be ordered propely.

PIVOT [Appointment Date];
Jan 13 '08 #4
Heh, to think something so simple was the answer. It worked perfectly puppy, thanks once again :)
Jan 13 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Donna Sabol | last post by:
First, I should start by saying I am creating a database to be used by some very impatient, non-computer literate people. It needs to be seameless in it's operation from their point of view. I...
12
by: Steve Elliott | last post by:
I have a query set up to gather together data between two specified dates. Shown in the query column as: Between #24/09/2004# And #01/10/2004# Is it possible to enter several different date...
1
by: mjobrien | last post by:
i created a query with the intention of creating a columnar (9 columns) report with the 10th column as a horizontal total of the records. i didn't think i needed a crosstab query because my first...
2
by: carl.barrett | last post by:
Hi, I'm back with the same question as I still can't get it to display my data the way I want it to. The table lists information about a perpetrator involved with an anti social behaviour...
4
by: Jean | last post by:
Hello, can the following be done? I have a one-rowed query, with the following column headings and values: M-1 M-5 M-7 B-C-1 B-D-2 B-D-4 E-5 R-4 --- --- --- ----- ----- ----- ...
2
by: Nenad Markovic | last post by:
Hi everybody, When executing a Crosstab Query I see only rows (defined in a row heading) that have values (defined in value field) in at least one column (defined as column headings). How can...
3
by: Col | last post by:
My table has rows that list type of pay with YTD pay for each as well as an employee ID number. I want to make the type of pay the column headings and have each row contain an employee id# and the...
1
by: c8tz | last post by:
This is a query I have created that picks up the top 3 dates for this data (for example) : Tree Pos2 Date 1 15 23/08/2005 1 20 12/02/2006 1 32 15/10/2006 ...
2
by: Jim Devenish | last post by:
I wish to create a crosstab query as the record source for a report. It needs to count data between selected dates which are entered by the user in a popup window. The following Select query...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.