473,406 Members | 2,633 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,406 software developers and data experts.

Set DataRange on a pivot table using a field "DateandTime"

I have almost no experience in ACCESS so am trying to get the system functioning with minimal operator input.

Currently I have managed to modify a database generated by a SCADA system using a query which generates a PIVOT table, grouped by DateAndTime, for all the desired data for Reporting purposes.

I have not been able to set the DateAndTime range of that data; so then a set group of data can be sent as a file to an archive location either as raw data or a report.

Is there a method for setting the DateAndTime range on a PIVOT table.

Field DateAndTime format from database is (dd.mm.yy hh:mm:ss AM/PM)
I was hoping to have an operator input a date (with NO time stamp) and to then fix a time range between 7:00 am and 7:00 pm, then from 7:00 pm to 7:00 am the following day. I think I should be able to do that once I can sort out the DateAndTime "filter"

Current CODE:

Expand|Select|Wrap|Line Numbers
  1. TRANSFORM sum(FloatTable.Val) AS Sumval
  2. SELECT FloatTable.DateAndTime
  3. FROM FloatTable INNER JOIN TagTable ON FloatTable.TagIndex=TagTable.TagIndex
  4. GROUP BY FloatTable.DateAndTime
  5. PIVOT TagTable.TagName In ("Report\Blend_RunMinHG",Report\Blend_RunMinLG,Report\Blend_RunMinMAG,Report\BW03_RunMin,Report\BW03_Total,Report\BW03_Total_HG,Report\BW03_Total_LG,);
Responses welcome.

Andrew
Jan 31 '07 #1
3 2010
MMcCarthy
14,534 Expert Mod 8TB
Hi Andrew, try the following:

First create a union query as follows ...
Expand|Select|Wrap|Line Numbers
  1. SELECT Val, DateAndTime, "7.00 am to 7.00 pm" As TimeRange
  2. FROM FloatTable
  3. WHERE TimeValue([DateAndTime]) Between #07:00# AND #19:00#
  4. UNION
  5. SELECT Val, DateAndTime, "7.00 pm to 7.00 am" As TimeRange
  6.  FROM FloatTable
  7.  WHERE TimeValue([DateAndTime]) Between #19:00# AND #07:00#
  8.  
For this example I've named the above query 'qry1'

Your crosstab query should now look like ...
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM sum(qry1.Val) AS Sumval
  2. SELECT qry1.DateAndTime, qry1.TimeRange
  3.  FROM qry1 INNER JOIN TagTable 
  4.   ON qry1.TagIndex=TagTable.TagIndex
  5. GROUP BY qry1.DateAndTime, qry1.TimeRange
  6. PIVOT TagTable.TagName In ("Report\Blend_RunMinHG",Report\Blend_RunMinLG,Report\Blend_RunMinMAG,Report\BW03_RunMin,Report\BW03_Total,Report\BW03_Total_HG,Report\BW03_Total_LG,);
  7.  
Jan 31 '07 #2
NeoPa
32,556 Expert Mod 16PB
I can't claim to understand the whole problem or solution very well, but the first query can be redone as :
Expand|Select|Wrap|Line Numbers
  1. SELECT Val,DateAndTime,
  2.        IIf(TimeValue([DateAndTime]) Between #07:00# AND #19:00#, _
  3.            '7.00 am to 7.00 pm', _
  4.            '7.00 pm to 7.00 am') As TimeRange
  5. FROM FloatTable
Thanks for the TimeValue() function btw - I always used Int() :o
Jan 31 '07 #3
NeoPa
32,556 Expert Mod 16PB
Having reviewed the whole query it looks like it can be done in one go, using Mary's basic code to work from.
Your CrossTab query should then look like :
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Sum(subQ.Val) AS SumVal
  2. SELECT subQ.DateAndTime,subQ.TimeRange
  3. FROM TagTable INNER JOIN
  4.      (SELECT TagIndex,Val,DateAndTime,
  5.           IIf(TimeValue([DateAndTime])
  6.               Between #07:00# AND #19:00#, _
  7.               '7.00 am to 7.00 pm', _
  8.               '7.00 pm to 7.00 am') As TimeRange
  9.       FROM FloatTable) AS subQ
  10.   ON TagTable.TagIndex=subQ.TagIndex
  11. GROUP BY subQ.DateAndTime, subQ.TimeRange
  12. PIVOT TagTable.TagName In('Report\Blend_RunMinHG',
  13.                           'Report\Blend_RunMinLG',
  14.                           'Report\Blend_RunMinMAG',
  15.                           'Report\BW03_RunMin',
  16.                           'Report\BW03_Total',
  17.                           'Report\BW03_Total_HG',
  18.                           'Report\BW03_Total_LG');
Jan 31 '07 #4

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

Similar topics

2
by: darrel | last post by:
I've built a control. At the top of my control, I have this: Imports Microsoft.VisualBasic Then, later, I call a function like this: DateTime.Now.Year.ToString() This works fine on my...
15
by: Phill. W | last post by:
Is anyone writing VB.Net (2003) code /without/ referencing the Microsoft.VisualBasic namespace(?), regardless of whether its Import'ed or not? The Powers That Be here are trying to introduce a...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.