MS Access Crosstab Query w/ Date Parameter Not Working Properly - ms-access

I have a MS Access Table with the following information
DA Attendance
Attendance ID (Key)
Date
DA
Attendance Record (Dropdown with 6 options)
Note
I am trying to create a cross tab query that will display the following:
Query Result Example
I am able to get the crosstab query without any date parameters to work as intended. The picture above is how it looks. However, when I add the parameter I get the following error: "The expression is typed incorrectly, or is too complex to be evaluated..." . I have a form in which the user inputs a specific day for which to create the query.
Query Design 1
Query Design 2
Raw Data Example
Attendance ID
DA
Date
Attendance Record
Note
1
65
2021-09-16
Present
2
37
2021-09-16
No Call No Show
No text response
3
25
2021-09-16
Tardy
1155 AM arrival
4
58
2021-09-16
Present
PARAMETERS [Forms]![DA Attendance Form]![DA_Attendance_Date] DateTime;
TRANSFORM Count([DA Attendance].[Attendance ID]) AS [CountOfAttendance ID]
SELECT [DA Attendance].DA
FROM [DA Attendance]
WHERE ((([DA Attendance].Date)=[Forms]![DA Attendance Form]![DA_Attendance_Date]))
GROUP BY [DA Attendance].DA
PIVOT [DA Attendance].[Attendance Record];

Figured out the issue. MS Access is acting as the front end for a SQL Server database. The field "Date" was declared as type Date() in SQL Server which for whatever reason pulled as "Short Text" in Access. Edited the field type to DateTime() in SQL Server and it solved the issues when running the query.

Related

Conditional Data fetch for a specific time window with SQL IF Statement

I have the below scenario. I have a table(name mytab1) in mysql database(using workbench community 6.3) which consists of columns like id, message and incidentdate(which is a date-time type). Mytab1 can contain more than 10k data. Now my requirement is to fetch the data by below condition :
Edit :
if{incidentdate < (current_systime - 2 hours)}
then fetch all the records from the table.
Else fetch the record whose incidentdate < (current_systime - 5 minutes).
I have used the below syntax for the same :
select if((select timestampdiff(minute,incidentdate,now()) from mytab1)>120,
(select message from mytab1),
(select message from mytab1 where incidentdate < date_add(now(), interval -5 minutes)))
as message;
Now, for the very first instance my table mytab1 contains below data :
id, message, incidentdate
-------------------------
A01, Incident_01, 2016-02-08 20:00:30
A02, Incident_02, 2016-02-08 20:10:20
conditional SQL query should able to fetch the above two data(as it is beyond two hours of current system time i.e. 2016-02-09 01:00:10). Now in the second instance a new data(one row for example) has entered in mytab1 table and mytab1 looks like below :
id, message, incidentdate
-------------------------
A01, Incident_01, 2016-02-08 20:00:30
A02, Incident_02, 2016-02-08 20:10:20
A03, Incident_03, 2016-02-09 00:55:30
And with this new data conditional SQL query should able to fetch data for complete third row only having message as "Incident_03".
With the above mentioned syntax of SQL query I am not able to fetch the data if there are multiple row in mytab1 and also not working if I want to fetch all the columns of mytab1 table. Would you kindly help with the conditional SQL syntax for this requirement please.

Line graph in Report Builder duplicating X-axis dates

I am attempting to create a line graph in Report Builder using the following data:
TRWR rental 85805 2013-09-14 13:02:54.900
TRWR rental 74415 2013-09-15 18:00:00.420
VRWR rental 83017 2013-09-14 10:03:43.597
VRWR rental 73984 2013-09-15 18:00:01.203
HRWR rental 83017 2013-09-14 14:03:15.497
HRWR rental 74005 2013-09-15 18:00:01.957
And the query that I am using is the following:
select ServerName, DatabaseName, FileSizeMB, DISTINCT PollDate from DBinfo
where DatabaseName IN (#Database) AND ServerName IN(#Servers) AND PollDate Between #StartDate AND #EndDate AND PhysicalFileName LIKE ('%mdf')
However, when I attempt to create the chart the X axis (dates) are duplicating. This is how I've set it up. Can anyone please show me how I can enter distinct dates. Please see the link for the image: http://imgur.com/7nhP3B6
Well even though it is not the best method for determining duplicates it gets the job done generally. I would guess the first step in debugging your method is your dataset is actually returning duplicates. You can avoid this by merely stating:
Select DISTINCT ....
versus
Select .....
This is merely SQL syntax telling the database engine to list a distinct row for each result.

number of records per day using grails

I have a grails application with a mysql database as the datasource. The mysql database is created and maintained by a third party. One of the tables 'visitinfo' contains 2 columns consisting of the 'userid' and 'logindatetime'.
userid is of type TEXT and logindatetime is of type 'datetime'.
In order to access the above table 'visitinfo', I have created a domain class 'VisitInfo' and mapped it to the mysql database table by which my grails application can easily store as well as retrieve data from the database.
On one of the pages, I am required to show visitor information for the last 30 days. So basically I am looking out for a solution to get number of visitors per day for the last 30 days. Something like this:
21-Jan-2012 ------ 36
22-Jan-2012 ------ 85
23-Jan-2012 ------ 115
24-Jan-2012 ------ 236
etc.
Also please note, that if a userid 'williamp' has 2 entries on a particular day, it should be counted as 2. So, am not looking out for uniqueness of users.
Any help will be appreciated.
I know nothing at all about grails. The MySQL query to obtain the desired result is as follows:
SELECT DATE_FORMAT(logindatetime,'%d-%m-%Y') dt
, COUNT(*) total
FROM visitinfo
GROUP
BY dt;
You want to use the countBy gorm method.
numLogins=VisitInfo.countByReleaseDateBetween(startOfDay,endOfDay)
This would need to be in a loop that calculates two date objects for each of the last 30 days. startOfDay would need a time value of 00:00:00:00 and endOfDay would need a time value of 23:59:00:00
I suggest following hql query to match your requirement
VisitInfo.executeQuery("select logindatetime, count(*) from VisitInfo group by logindatetime")

Excel VBA Report, Selecting Cells by a criteria

I have this Excel
now i want to make some reports using a VBA Macro
Report 1 (select all tasks)
Select the number of total tasks no matter if they are completed or not
IMPORTANT! Keep in mind that here are 5 tasks, in another excel may be 20 30 , but all have the same format C6 - task_id, D6 - task_name, E6 task_name ... and so on
Report 2 (select all WHERE completed is 100%)
Select the number of total tasks where completed column is 100%
IMPORTANT! Keep in mind that here are 5 tasks, in another excel may be 20 30 , but all have the same format C6 - task_id, D6 - task_name, E6 task_name ... and so on
Report 3 (select all users and retrive information about their productivity)
Here basicaly i need something like
SUM(I6:I10) - SUM(K6:K10) WHERE task_given_to = 'OM'
SUM(I6:I10) - SUM(K6:K10) WHERE task_given_to = 'MN'
SUM(I6:I10) - SUM(K6:K10) WHERE task_given_to = 'NM'
IMPORTANT! Keep in mind that here are 5 tasks, in another excel may be 20 30 , but all have the same format C6 - task_id, D6 - task_name, E6 task_name ... and so on
Any help with that?
I must say, in SQL it would be easy ...
Is there any requirement to use VBA ? Unless there is something I am missing, a simple pivot table would be able to do that.
Just put the task name as the row field.
Apply a filter on completion.
User as row field, productivity as data, task type as column.
Isn't it what you are trying to achieve ?
Oh and FYI if this does come from Access you can use MS Query.
Data => Other sources => MS Query => Access database
Then you can just use an SQL query to retrieve data. I'd then make 3 data sheets with 3 different queries and 3 report sheets which would format the data to a more report-like format.

A query to combine multiple row values into one field in MS-Access 2003? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Combine rows in Access 2007
If I have two tables: let's say OrderStatus and Comments, how can I sum up all comments which are made related to one order, so that I can put them into one field?
Tabel OrderStatus:
OrderID OrderStatus OrderDate
64 OK 13.08.2011
77 Deleted 21.06.2011
99 OK 18.04.2011
Table Comments:
CommID CommOrder CommText
1 64 "EAN 304"
2 64 "resent"
3 64 "no. 499"
4 99 "in stock"
5 99 "EAN 111"
What I want:
OrderID OrderStatus Comments
64 OK "EAN 304, resent, no. 499"
99 OK "in stock, EAN 111"
The total number of comments related to an order status is unknown.
I am trying to achieve this with Access SQL-subqueries. I already managed with own VBA routines called from the query builder but the OrderStatus table has more than 30,000 records and VBA is too slow (takes more than 10 minutes to generate a report). In Microsoft Access, SQL is much faster than VBA but can be complicated.
From Access 2007 on, Microsoft has included multivalued fields, however I'm using Access 2003 which isn't capable of automatically listing multiple values comma-separated.
Thanks for your help!
VBA is the way to go. But, I wouldn't call it from the query builder. I would add a "Comments" field to your original table, and make a stand-alone VBA function using the Recordset object to loop through the records in the second table, and paste the data in the Comments field. A function like this for just 30,000 records should run very quickly.