MS ACCESS application get crashing after applying filter to certain queries - ms-access-2010

Currently I am developing an Access 2013 based Application for tracking evaluation information of the school students. The database contains only 3 simple tables:
tblSubjects = Contains different subject information
tblStudents = Contains student's personal information
tblMarks = Contains subject wise evaluation marks for each student
and few other queries based on these 3 tables. Now I have a (bit ugly) sql query like following:
SELECT tblStudents.*,
(SELECT COUNT(*) FROM qryPapers WHERE qryPapers.STUDID=tblStudents.STUDID) AS PAPER_COUNT,
(SELECT SUM(MR_TOTAL) FROM qryPapers WHERE qryPapers.STUDID=tblStudents.STUDID) AS ALL_TOTAL,
(SELECT MIN(MR_TOTAL) FROM qryPapers WHERE qryPapers.STUDID=tblStudents.STUDID AND qryPapers.PAPER_TYPE LIKE 'E?') AS MIN_ELEC,
(SELECT COUNT(*) FROM qryPapers WHERE qryPapers.STUDID=tblStudents.STUDID AND qryPapers.PAPER_TYPE LIKE 'A?') AS LANG_PS,
(SELECT COUNT(*) FROM qryPapers WHERE qryPapers.STUDID=tblStudents.STUDID AND qryPapers.PAPER_TYPE LIKE 'E?') AS ELCT_PS,
IIf([PAPER_COUNT]>5,ALL_TOTAL-MIN_ELEC,ALL_TOTAL) AS [GT],
IIf([LANG_PS]=2 And [ELCT_PS]>=3,'PASS','FAIL') AS STATUS
FROM tblStudents;
The Problem is, whenever I try to run a filter on the STATUS field of this query (Like When STATUS='PASS') the entire ACCESS is first STOPES RESPONDING! and then SHUTS DOWN and RESTARTS.
I have no idea what is going on here. I have seen far more complex queries running perfectly well, but not this one. Any help will be appreciated.

I've experienced this a lot in Access. I don't know the cause of the problem but I just export the query to Excel or create a table based on the query to apply filtering.

Related

PeopleSoft Query - finding people without leave type

I'm working with PeopleSoft's query manager and I'm having trouble creating a report that will find all active employees who do not have a certain leave type.
I have the two tables (Employees - Non terminated Employees and Leave_Accrual-EE). They are left outer joined. The field in question is PLAN_TYPE. Now, I've tried creating a filter to pull in all employees who do not have plan type 54. The criteria is B.PLAN_TYPE not equal to 54, but that still brings up everyone, it just doesn't bring up the row for 54.
I feel like I'm missing something obvious - maybe I have to create a subquery? If so, I have never done this in PeopleSoft.
Anyone have any advice?
Original SQL screenshot.
UPDATED
This is less of a PeopleSoft question, and more of a SQL question.
The problem you have been running into is that you are doing a per-row filter and excluding only rows that have the undesirable code.
What you need to do instead is exclude all rows for a user that has the undesirable code in any row.
This can be done with a NOT IN or NOT EXISTS query.
e.g.
SELECT EMPLID
FROM TABLE1
WHERE
EMPLID NOT IN
(
SELECT EMPLID
FROM TABLE1
WHERE CODE = 123
)
/
alternately
SELECT A.EMPLID
FROM TABLE1 A
WHERE
NOT EXISTS
(
SELECT B.EMPLID
FROM TABLE1 B
WHERE
B.CODE = 123
AND B.EMPLID = A.EMPLID
)
/
See this SQL Fiddle example to test out the SQL:
http://sqlfiddle.com/#!4/2b0f6/7
To do this in PS Query, you could do this by adding a criteria with a subquery on the right side of the equivalence.
Here is some documentation:
Home > PeopleSoft PeopleTools 8.53 > PeopleSoft Query > Working with Subqueries

Oracle 11g fetch values using offset value

I am trying to fetch set of records from the database part by part.
I tried to use Limit and fetch but it seems like it does not working with oracle 11g. Is there any alternative solution to do this. I have tried many in google results but nothing is working properly.
You can use this query and do what u want.
SELECT A.*
FROM (SELECT A.*, ROWNUM ROWNUMBER
FROM Table1 T
WHERE ROWNUM <= TO) T
WHERE ROWNUMBER > FROM;
FROM is from which number and TO is to which number
A Sound application is based on sound design. Kindly check if you are trying to achieve a procedural requirement using an SQL. If yes, it is better to use PL/SQL instead of SQL.
Create a cursor using the required SQL without any limits.
Create a type of associative array to hold the batch records.
Create an associative array using the type created above
Open and loop the cursor.
FETCH created_cursor BULK COLLECT INTO created_associated_array LIMIT ;
Hope this helps.

Strange result in DB2. Divergences queries

A strange thing, that I don't know the cause, is happenning when trying to collect results from a db2 database.
The query is the following:
SELECT
COUNT(*)
FROM
MYSCHEMA.TABLE1 T1
WHERE
NOT EXISTS (
SELECT
*
FROM
MYSCHEMA.TABLE2 T2
WHERE
T2.PRIMARY_KEY_PART_1 = T1.PRIMARY_KEY_PART_2
AND T2.PRIMARY_KEY_PART_2 = T1.PRIMARY_KEY_PART_2
)
It is a very simple one.
The strange thing is, this same query, if I change COUNT(*) to * I will get 8 results and using COUNT(*) I will get only 2. The process was repeated some more times and the strange result is still continuing.
At this example, TABLE2 is a parent table of the TABLE1 where the primary key of the TABLE1 is PRIMARY_KEY_PART_1 and PRIMARY_KEY_PART_2, and the primary key of the TABLE2 is PRIMARY_KEY_PART_1, PRIMARY_KEY_PART_2 and PRIMARY_KEY_PART_3.
There's no foreign key between them (because they were legacy ones) and they have a huge amount of data.
The DB2 query SELECT VERSIONNUMBER FROM SYSIBM.SYSVERSIONS returns:
7020400
8020400
9010600
And the client used is SquirrelSQL 3.6 (without the rows limit marked).
So, what is the explanation to this strange result?
Without the details (including, at least, the exact Db2 version and DDL for both tables and their indexes) it can be just anything, and even with that details only IBM support will be really able to say, what is the actual reason.
Generally this looks like damaged data (e.g. differences in index vs table data).
Worth to open the support case with IBM.

In Access, is it possible to select fields from similar tables in front end & back end copies on different drives?

I have a split Access 2010 database. Users have a copy of this database on their laptops and there is a main copy that resides on the I: drive server. Two tables exist for input on all copies: tblMedData and tblMyMedData. Users can perform a synchronization that moves the tblMyMedData data from their laptops into the tblMedData table on the I: drive server. tblMedData is then copied back to the tblMedData table on the laptop, so they have the latest data residing on their laptop.
The problem we're facing: if a change is made in the tblMedData table on the server, this change gets overwritten during the synchronization. During the synchronization, I've tried using a select query that checks for medications that exist in both the laptop tblMedData table and the server tblMedData table and if there are any differences between these records, but I can't figure out how to do this? Here's what I have so far:
SELECT tblMedData.* AS tblLaptopMeds, tblMedData.* AS tblServerMeds, tblMedData.Ratio,
tblMedData.Duration, tblMedData.Withdrawal, tblMedData.WaterOrInject, tblMedData.Deleted
FROM [C:\FolderName\DB.accdb].tblMedData AS tblLaptopMeds INNER JOIN
[I:\FolderName\Folder\DB_be.accdb].tblMedData AS tblServerMeds ON tblLaptopMeds.InvNo =
tblServerMeds.InvNo
WHERE (((tblLaptopMeds.Ratio)<>tblServerMeds!Ratio)) Or (((tblLaptopMeds.Duration)
<>tblServerMeds!Duration)) Or (((tblLaptopMeds.Withdrawal)<>tblServerMeds!Withdrawal))
Or (((tblLaptopMeds.WaterOrInject)<>tblServerMeds!WaterOrInject)) Or
(((tblLaptopMeds.Deleted)<>tblServerMeds!Deleted)) Or (((tblLaptopMeds.Ratio)
<>tblServerMeds!Ratio)) Or (((tblLaptopMeds.Duration)<>tblServerMeds!Duration)) Or
(((tblLaptopMeds.Withdrawal)<>tblServerMeds!Withdrawal)) Or
(((tblLaptopMeds.WaterOrInject)<>tblServerMeds!WaterOrInject)) Or
(((tblLaptopMeds.Deleted)<>tblServerMeds!Deleted)) OR
(((tblLaptopMeds.ChangedBy)<>tblServerMeds!ChangedBy));
Does anyone have suggestions? Am I making this too complicated?
Here is a snippet of searching for missing values:
select * from YourTable a
where a.YourIDField not in
(select b.YourIDFieldfrom YourTable b
where a.YourIDField= b.YourIDField)
I'm not sure if Not In will work in Access (esp if you're examining multiple fields), so try this if it doesn't:
select * from YourTable a
where a.YourIDField not exists
(select b.YourIDFieldfrom YourTable b
where a.YourIDField= b.Your
See this post for similar answer
I think if you look into what I posted along with Selecting from 2 databases on different servers you should be able to go figure it out fairly quickly.

Poor SP performance from ASP.NET

I have a stored procedure that handles sorting, filtering and paging (using Row_Number) and some funky trickery :) The SP is running against a table with ~140k rows.
The whole thing works great and for at least the first few dozen pages is super quick.
However, if I try to navigate to higher pages (e.g. head to the last page of 10k) the whole thing comes to a grinding halt and results in a SQL timeout error.
If I run the same query, using the same parms inside studio manager query window, the response is instant irrespective of the page number I pass in.
At the moment it's test code that is simply binding to a ASP:Datagrid in .NET 3.5
The SP looks like this:
BEGIN
WITH Keys
AS (
SELECT
TOP (#PageNumber * #PageSize) ROW_NUMBER() OVER (ORDER BY JobNumber DESC) as rn
,P1.jobNumber
,P1.CustID
,P1.DateIn
,P1.DateDue
,P1.DateOut
FROM vw_Jobs_List P1
WHERE
(#CustomerID = 0 OR CustID = #CustomerID) AND
(JobNumber LIKE '%'+#FilterExpression+'%'
OR OrderNumber LIKE '%'+#FilterExpression+'%'
OR [Description] LIKE '%'+#FilterExpression+'%'
OR Client LIKE '%'+#FilterExpression+'%')
ORDER BY P1.JobNumber DESC ),SelectedKeys
AS (
SELECT
TOP (#PageSize)SK.rn
,SK.JobNumber
,SK.CustID
,SK.DateIn
,SK.DateDue
,SK.DateOut
FROM Keys SK
WHERE SK.rn > ((#PageNumber-1) * #PageSize)
ORDER BY SK.JobNumber DESC)
SELECT
SK.rn
,J.JobNumber
,J.Description
,J.Client
,SK.CustID
,OrderNumber
,CAST(DateAdd(d, -2, CAST(isnull(SK.DateIn,0) AS DateTime)) AS nvarchar) AS DateIn
,CAST(DateAdd(d, -2, CAST(isnull(SK.DateDue,0) AS DateTime)) AS nvarchar) AS DateDue
,CAST(DateAdd(d, -2, CAST(isnull(SK.DateOut,0) AS DateTime)) AS nvarchar) AS DateOut
,Del_Method
,Ticket#
,InvoiceEmailed
,InvoicePrinted
,InvoiceExported
,InvoiceComplete
,JobStatus
FROM SelectedKeys SK
JOIN vw_Jobs_List J ON j.JobNumber=SK.JobNumber
ORDER BY SK.JobNumber DESC
END
And it's called via
sp_jobs (PageNumber,PageSize,FilterExpression,OrderBy,CustomerID)
e.g.
sp_Jobs '13702','10','','JobNumberDESC','0'
Can anyone shed any light on what might be the cause of the dramatic difference in performance between SQL query window and an asp.net page executing a dataset?
Check out the "WITH RECOMPILE" option
http://www.techrepublic.com/article/understanding-sql-servers-with-recompile-option/5662581
I have run into similar problems where the execution plan on stored procedures will work great for a while, but then get a new plan because the options changed. So, it will be "optimized" for one case and then perform "table scans" for another option. Here is what I have tried in the past:
Re-execute the stored procedure to calculate a new execution plan and then keep an eye on it.
Break up the stored procedure into separate stored procedures of each option such that it can be optimized and then the overall stored procedure simply calls each "optimized" stored procedure.
Bring in the records into an object and then perform all of the "funky trickery" in code and then it gives you the option to "cache" the results.
Obviously option #2 and #3 is better than option #1. I am honestly finding option #3 is becoming the best bet in most cases.
I just had another option 4. You could instead of performing your "inner selects" in one query, you could put the results of your inner selects into temporary tables and then JOIN on those results. I would still push for option #3 if possible, but I understand that sometimes you just need to keep working the stored procedure until it "works".
Good luck.

Resources