473,765 Members | 1,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Specifying date headings in Crosstab Query

10 New Member
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 2318
puppydogbuddy
1,923 Recognized Expert Top Contributor
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
odavison
10 New Member
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 Recognized Expert Top Contributor
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
odavison
10 New Member
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
7587
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 want them to do as little as possible when they run their reports. I have a crosstab query that displays usage of items for each month. It looks pretty much like this: ITEM DESC UM 12/02 1/03 2/03 3/03 ...ETC. 1 Solution ...
12
6392
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 ranges, ie between 24/09/2004 and 01/10/2004 together with 05/10/2004 and 07/10/2004 ? If I enter the "Between" criteria on different lines it returns no data.
1
367
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 column is just for row title constants identifying the rows on the report. the report should look like this: Hearing ABIs Vision Mobility etc....9th Total Primary Unweighted 9999 9999 9999 9999 ........... 999999
2
2255
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 order. The table contains personal information about the individual as well as (here is where the letter dates comes in:) e.g.
4
2615
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 --- --- --- ----- ----- ----- --- --- 4 5 1 2 1 3 7 3
2
2935
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 I make a Crosstab Query that shows all rows, regardless they have values in column headings. For instance, the result that I get now is like this
3
5403
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 YTD amount for each type of pay. Currently each type of pay is a different records - need the employee ID as one records with all types of pay listed. Thoughts?
1
2656
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 17 23/08/2005 2 18 12/02/2006
2
3405
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 works: SELECT Tasks.EnquirySourceID, Tasks.BusinessUnitID, Count(Tasks.TaskID) AS CountOfTaskID FROM Tasks WHERE (((Tasks.TaskDate)>=!!)) GROUP BY Tasks.EnquirySourceID, Tasks.BusinessUnitID;
0
9566
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10153
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6646
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5272
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3530
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2800
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.