Linked Count Queries / One Null Query Blanks Out All The Rest.
Dec 17, 2007
Hi all,
Desperate for help on this.
The query below ran like a charm for this years database which was full of entries, but when I did a quick test run for next year with limited entries the 'Temp' table fields were all blanked. All the individual queries, 1 through 9, work fine on their own and work fine in this linked form when there is enough data in the database to cover all the fields.
Apparently if only one query is blank all the fields will be blank.
For instance if there are multiple registered households, table ‘1’ would normally show a count of those households, but if none of those households have children, table '2' which counts children will be blank and in turn blank out all the rest of the fields including table ‘1’.
I've tried the ‘is null, '=0" and ‘nz’ routines on the Count(Tablename.Fieldname)'s, but can't seem ‘to get them to output a value of 0 in the null fields. I must be doing something wrong. Any and all help would be very much appreciated.
SELECT Year(Now()) AS ProjectYear, [1].CountOfClaimID AS Households, [2].CountOfPersonID AS Children, [3].CountOfPersonID AS Participants, [4].CountOfSponsorID AS SponsorsTotal, [5].CountOfHouseholdID AS Sponsored,
[6].FamiliesWithChildren, [7].SponsoredFood, [8].SponsoredGifts, [9].SDSD
INTO Temp
FROM
(SELECT Count(Household.ClaimID) AS CountOfClaimID FROM Household GROUP BY Household.RegStatus
HAVING (((Household.RegStatus)=-1))) AS 1,
(SELECT Count(Members.PersonID) AS CountOfPersonID
FROM Household INNER JOIN Members ON Household.HouseholdID = Members.HouseholdID
GROUP BY Household.RegStatus, Members.Status HAVING (((Household.RegStatus)=-1) AND ((Members.Status) = "Child" ))) AS 2,
(SELECT Count(Members.PersonID) AS CountOfPersonID FROM Household INNER JOIN Members ON Household.HouseholdID = Members.HouseholdID
GROUP BY Household.RegStatus HAVING (((Household.RegStatus)=-1))) AS 3,
(SELECT Count(Sponsors.SponsorID) AS CountOfSponsorID
FROM Sponsors GROUP BY Sponsors.SponsorStatus HAVING (((Sponsors.SponsorStatus)=-1))) AS 4,
(SELECT Count(Sponsorship.HouseholdID) AS CountOfHouseholdID FROM Sponsors INNER JOIN
Sponsorship ON Sponsors.SponsorID = Sponsorship.SponsorID GROUP BY Sponsors.SponsorStatus, Sponsorship.SponsorshipYear
HAVING (((Sponsors.SponsorStatus)=-1) AND ((Sponsorship.SponsorshipYear)=Year(Now())))) AS 5,
(SELECT Count([Table0].HouseholdID) AS FamiliesWithChildren
FROM (SELECT Households_All.HouseholdID, IIf([Children]>0,1,2) AS FamChildren
FROM Households_All
GROUP BY Households_All.HouseholdID, Households_All.Children
HAVING (((IIf([Children]>0,1,2))=1))) as Table0) AS 6,
(SELECT DISTINCT Count(Household.HouseholdID) AS SponsoredFood
FROM Household INNER JOIN Sponsorship ON Household.HouseholdID = Sponsorship.HouseholdID
GROUP BY Household.RegStatus, Sponsorship.SponsorshipYear, Sponsorship.Food
HAVING (((Household.RegStatus)=-1) AND ((Sponsorship.SponsorshipYear)=Year(Now())) AND ((Sponsorship.Food)=-1))) AS 7,
(SELECT DISTINCT Count([Household].[HouseholdID]) AS SponsoredGifts
FROM (Household INNER JOIN Sponsorship ON [Household].[HouseholdID]=[Sponsorship].[HouseholdID]) INNER JOIN (SELECT Households_All.HouseholdID, IIf([Children]>0,1,2) AS FamChildren
FROM Households_All
GROUP BY Households_All.HouseholdID, Households_All.Children
HAVING (((IIf([Children]>0,1,2))=1))) as Table0 ON [Household].[HouseholdID]=[Table0].[HouseholdID]
GROUP BY [Household].[RegStatus], [Sponsorship].[SponsorshipYear], [Sponsorship].[Gifts]
HAVING (((Household.RegStatus)=-1) AND ((Sponsorship.SponsorshipYear)=Year(Now())) AND ((Sponsorship.Gifts)=-1))) as 8,
(SELECT DISTINCT Count(Household.HouseholdID) AS SDSD
FROM Household
GROUP BY Household.RegStatus, Household.SDSD
HAVING (((Household.RegStatus)=-1) AND ((Household.SDSD)=-1))) as 9;
I was trying to filter a word using Not Like "word" in my query cirteria, some data is blank also, From this record i want to retrieve the result. But when i use Not Like Criteria, filter is working but blanks columns are also filtered.
I want to display all records (including blanks) except what i shown in the criteria.
I have a count column in this query, and i would like for it to return a zero instead of null if it doesnt find anything to count. Here's the SQL for the query.
Code: SELECT Documents.Status, Count(Documents.Document) AS CountOfDocument FROM [Request Details] INNER JOIN Documents ON [Request Details].Request_ID = Documents.Request_ID GROUP BY Documents.Status, [Request Details].Contract, [Request Details].CDRL, [Request Details].Change_Cycle HAVING (((Documents.Status)="No Record") AND (([Request Details].Contract)=[Forms]![Report Runner]![Contract]) AND (([Request Details].CDRL)=[Forms]![Report Runner]![CDRL]) AND (([Request Details].Change_Cycle)=[Forms]![Report Runner]![ChangeCycle]));
I am trying to create a clean database and code to generate a report.
I am trying to count the number of null fields in one of my queries:
However, because of this expression, I cannot carry other fields with it. So the end result looks like:
But I would really like it to spit out the following information:
Total Not Fixed: 241 Department: Sustaining Eng
is there a way to create an SQL query to simply add data: I have tried the following:
Code:
ALTER TABLE qrySustainingEngNotFixed2 ADD Dept TEXT(25) Insert Into qrySustainingEngNotFixed2 (Dept) Values (Sustaining Eng) SELECT TotalNotFixed, Dept FROM qrySustainingEngNotFixed2;
The above isn't working. Keep in mind that I want this is just for display purposes. I pondered making a custom table and then making a Union Query, but I'm trying to do this all in one SQL statement.
I have a database that I maintain the history of our football league in. What I am trying to do is count each team and the number of wins in each year
The query works fine except in the cases where the team had ZERO wins. Then of course it returns nothing and screws up the other queries when there is a hole for a year.
2 Tables in the database
INFORMATION TEAM YEAR (other fields not relevant)
SCORES TEAM YEAR RESULT (either WIN, LOSS or TIE) (other fields not relevant)
I want to count the number of wins and return it to this query EVEN IF THE NUMBER OF WINS IS ZERO (0).
In 2002 Westside was 0 wins -11 losses and the query not finding any WINS in 2002 did not return a record.
How do you get the query to show 2002 Westside 0
========================== Current SQL Query SELECT Information.Year, Information.Team, Count(Scores.Result) AS CountOfResult, Scores.Result FROM Scores INNER JOIN Information ON (Scores.Year = Information.Year) AND (Scores.Team = Information.Team) GROUP BY Information.Year, Information.Team, Scores.Result HAVING (((Information.Year)>2000));
I want to combine six different memo fields into one. I found this code and it works to combine two fields so I edited to add a third and it does not do anything.
I have a list box on a form which uses the following SQL to pull the list items from a table :
SELECT DISTINCT tblMyTable.MyField FROM tblMyTable ORDER BY tblMyTable.MyField;
For some reason, during testing, the first two items on the list are blanks. I am quite happy for one blank to be returned at the top of the list (as this would easily identify for the user any records for which this field has not yet been completed, which is a good thing) but I can't understand why it would appear twice?
Why doesn't the DISTINCT command ensure any blank entries only appear once?
Incidentally, I have a subform which populates on the back of selections from the list boxes, so I can quickly see the corresponding records which generate these blanks. What's puzzling me is that the same records show for both blanks on the list - suggesting it is the same value repeating itself (and not, say, "" vs " ", for example, which was what I originally suspected...)
i have a slight problem with my reporting data base.
we have currently set, up a database, which has a number of linked tables.
the problem is that, when the macro is run, and the report is poulated, it is not reporting the true amount, in one of the fileds.
we have worked out that, you cant have a is null command with linked tables, becuase it will bring incomplete data, and the zero length must be set to yes.
is there a way round this, i not that offay, with SQL, but i am getting the concept of it.
also, we have discovered it is the imported data, i.e. from another data base that seems to be the culprit. Is there something i can do to transform the data to bring me the count of null values in a partucular field?
I have a form which a user can select upto 3 different options to search the main database.
The main table has: RVA Date Council Introducer PS NO Period Asset Description Current Cost SSAP21 Position
The three fields the user can search on is: Council PS No. Asset Description
I have created 3 individual queries to find the records for each of the above, as the other two choices could be left blank.
Not sure if one super query can be done to show the records based on the user input (as I say one or two choices could be left blank).
So far I have managed to get a main query (based on the 3 other queries) to work on all choices made by the user except Asset Description with the other two left blank.
I have made relationships between the three queries on the main query. Linking Council,PS No. & Asset Description to each other.
Almost there, just need the main query to work on the user selecting Asset Description only.....
SysID PersonData " " " " AddressData " " " " " " " " " TelephoneData " " " " Year (this is 1 or 2)
I'm taking each component Person, Address, Telephone info and making a compacted table of each (i.e. lots of Jane Does etc, appear in both years) Each table with have a URN
I then need to update the big table with the URN so move onto another part of getting this data into a usable format.
Basically what follows is my question on how to get the URN's back into the table:
Is there a quicker way (or a way I'm not seeing) of doing the following.
I have a set of data 'tblDatabaseTable, say:
ID Field1 Field2 Field3 Field4
In the database.
I have an imported file which will be tblImportTable, same deal without the ID:
Field1 Field2 Field3 Field4
I need to compare the data on each table:
SELECT * FROM tblDatabaseTable INNER JOIN tblDatabaseTable ON tblDatabaseTable.Field1 = tblImportTable.Field1 AND tblDatabaseTable.Field2 = tblImportTable.Field2 AND tblDatabaseTable.Field3 = tblImportTable.Field3;
Works great as long as all the fields have values in.
Is there a way to compare the tables and get results as:
Database Ian MacConnell null
Import Ian Macconnell null
Match!
without doing something like:
SELECT IIf(IsNull([Field1]),' ',[Field1]), IIf(IsNull([Field2]),' ',[Field2]), IIf(IsNull([Field3]),' ',[Field3]) FROM DatabaseTable
SELECT IIf(IsNull([Field1]),' ',[Field1]), IIf(IsNull([Field2]),' ',[Field2]), IIf(IsNull([Field3]),' ',[Field3]) FROM ImportTable
before comparing them???
Phew, hope that all makes sense, very long day and I'm........
I have a form that feeds information to a query which in turn sets up a report. For clarity i will list out in basic terms what I have
Input Form - Check Box to activate/De-activate a text field [chk-active] - Text field for a parameter [txt-Parameter]
the query has a column that has null values from the originating table. These values will be added a t a later date, but need to be queried and reported at some business intervals.
In the query criteria for this column, I have the following Criteria
Like IIF([Forms]![ReportGenerator]![chk-Active]=0, "*", [Forms]![ReportGenerator]![txt-Parameter])[/I][/I]
I have tried for the last 5 hours to figure out how to write the formula to be able to get the blank entries to show up as well but have had no luck.
Been taking abreak from Access for a few years now and cant get my head round my problem.
I have been asked to manipulate data from a Training Recods database.
Basically, training consists of 26 modules, there are currently 180 people who need training. Each person has been assigned a unique number, once a module has been completed, the date it was completed is entered into the database. There are currently lots of modules which havent been completed, what I need is a way of pulling that data from the DB.
I need to know how many people need to complete each module. For example, Module 1 might need to be completed by 15 people, Module 2 might need to be completed by 27 people etc.
I have enclosed the DB with the table and the form that I am looking to populate with the data.
Anyone have any ideas, I just can't get my head round it!!!!
I know how to count records so that null records would be counted but I do not know how to do this:
I have customers and works. I want to create a query that will show ALL customers and number of works done for that customer (sometimes there is no work done for customer).
I have a form which users can toggle whether they want to only see entries that has data in a certain field. Previously I have set up a separate query with a hardcoded 'Is Not Null' in the criteria, and set the form to call the different queries based on the status of a toggle button. This time there is 22 queries that need to be modified so I'm hoping there's a better way.
I have a hidden textbox on my form that has value "Is Not Null" or Null based on the position of the toggle button.
In my query for the field criteria I have [Forms]![MainForm].[txtCriteria] where txtCriteria is the textbox previously mentioned.
Database query. I need the query to count the records of a field and display a number for the records of the field. For instance, one field is [Genre] and the other is [Show]. The query needs to list the Genres along with the number of shows for each genre. I've been able to just use the query design and add the genre field and I can add the show field, use totals count which gives me the genre counts the number of shows. My problem is the null. Some genres don't have a show listed so the genre doesn't even show up in the result. If I could get the the genres that have null shows to result a 0 it would be perfect.
My training database requires me to identify each training record in the tblEmpTrainHist table as either "Compliant" or "Delinquent". I thought a simple calculation in my query:
would do the trick. However, I did not consider the records where the employee has not yet completed the training and the field [DateReceived] is Null. There are two considerations: those employees who have no [DateReceived], but have not yet reached the DateDue (Compliant); and those employees who have exceeded the DateDue (Delinquent).
I have a delete query where i want to delete only the row that contains the max value of the IDnum field from the table STM, where it links two tables on CellTell
I currently have this:
DELETE DISTINCTROW STM.*, STM.IDNum FROM dpl_00c_tbl_StmCellDups INNER JOIN STM ON dpl_00c_tbl_StmCellDups.STM_CellTel = STM.CellTel WHERE (((STM.IDNum)=(select max(IDNum) from `STM`)));
It doesn't want to throw out any values when i run it, or view it.
I have the query below and it returns the number of cases for eache of the case status (open, closed or private) Some of the cases have no status, the field is empty. Is there a way to count the number of cases which have no status in the status field?
Can someone tell me how to do this?
SELECT Count([Report table part one].CaseStatus) AS CASES, [Report table part one].CaseStatus AS STATUS
I need to count all values after "0" or null value of a rows in query of a table.I have attach Table.gif..Actually in need to get the duration of debts continue of a supplier as following sample.
I have been working on an application where I am collecting survey data in a database. There are multiple survey tools available to the user, and it's possible to complete multiple survey tools in the survey.My problem is, it's possible for the surveyor to complete some tools on one day and other tools on another day. I am having problems with trying to figure out how to add a tool that has not been previously added and keep in the same survey which is all held under a single Survey Number.
The first step in the function is to set a Record Number temporary variable based on whether or not the tool has been used (it's possible to use multiple instances of a survey tool, so need to know if the Record Number is '1', or the next number in the sequence.I've been trying to do this by checking a query for a Null and setting the temporary variable using something like:
IF ISNull("RecordNumber","qryRecordHeader") Then '1' Else DLast("RecordNumber","qryRecordHeader") +1 End IF
The second half works just fine, so if there is a previous record, it will add. But if it's Null, it doesn't work.I'm trying to avoid opening a temporary form to run the query and checking a field. Is there a way around that?
I have a query that is search for fields in a table that are either
1 - High 2 - Medium 3 - Low
I have a query that counts these and then puts the results into pie charts on a report.
However, when there is no "1 - High" value in the table against a paricualr criteria, obviously the quiery has nothing to look for an does not show a 0 value against the criteria but simply omits it (correctly) form the results.
This does affect the pie charts though which I want to show red for High, yellow for Medium and green for Low.
Therefore I need the query to show all criteria search results include 0 values, or to understand how I can colour code the series rather than the segments on the report.
I have a question about errors on null value.I have made a small database for tryout, it has to be implemented in another one.And the small database is working.I have one table where there is one field called BatchInput.I scan a barcode into it and let two query's breaking it apart. I scan this batch into the table field
BatchInput: 20 MAY 2004H149-082-79 A4147011A05
Then I have my first query (Qrybreak1) extracting the date and deleting H14
And query (QryResult) even wont start, giving a popup with Invalid procedure call..How could I handle Null on the part where there is no space after the partnumber (missing Certnumber)?
I had an issue with writing LIKE statements in query criteria yesterday [URL]....
The answer they gave worked perfectly when I only used a single table in the query. But as soon as I did an INNER JOIN with two other tables, now I get parameter value prompts when I open frmSearch, and instead of seeing ALL my records when the controls are left null, I get only the first record in the table.
Here's the SQL of the query, can you point out what I messed up? NOTE that this SQL was 'written' by Access.. as I used the Query builder to set all the 'Like or Is Null' statements, then clicked SQL and sorta formatted the code so I can see what I'm looking at (instead of superthick wall-o-code):
Code: SELECT tblPeople.name, tblPeople.num FROM (tblPeople INNER JOIN tblAddresses ON tblPeople.name = tblAddresses.name) INNER JOIN tblPets ON tblPeople.name = tblPets.name
[code]....
Basically, this is a searchable database of participants in a pet-adoption program, along with the participants' pets history and address history (hence the linked tables as opposed to additional columns in one single table for pets and addresses... there are more than one in some cases). The frmSearch allows a person to run quick searches based upon ANY item in the database, such as name, pets, addresses, pet age, pet type, county of residence, etc. I need to be able to pick ANY field on frmSearch and type a value, and have the qrySearch return records for ANY record's related column wherein any part of it matches what I typed.
The statements as written worked PERFECTLY right up until I added the INNER JOIN. Now I get a set of parameter value prompts for every field on frmSearch that's referenced in the SQL for EACH table I linked to tblPeople, and if I leave everything null and click Search, I want to see EVERY person, but I'm only seeing the very FIRST person in tblPeople.
I am currently creating an Access 2007 database for calculating salesperson commissions. I have a table with 5 fields I'm working with: SalesRep, SOWRep, TerritoryRep, Period and Commission. I am trying to build a query that will calculate commission for a salesperson for each record where their name appears in one of the first three fields. Each time their name appears, they get the commission listed in the Commission field for the stated Period. I have managed to do this part successfully. My problem now is that I am creating a query that will sum all of their commissions by Period. I have run into a situation where sometimes a salesperson will not appear in one of the rep fields, resulting in NULL values in the previous queries. How can I create a final query that will sum correctly even if there are NULL values returned on the previous queries?
Here is what I have so far:
November: Avg((SELECT [SumOf1/3GM$s] FROM [BaxterActualMargin1] WHERE [Period] Like "November*")+(SELECT [SumOf1/3GM$s] FROM [BaxterActualMargin2] WHERE [Period] Like "November*")+(SELECT [SumOf1/3GM$s] FROM [BaxterActualMargin3] WHERE [Period] Like "November*"))