Complicated Nested Queries / References

May 8, 2012

I am trying to create a database which crosschecks specifications against building codes. My problem is that it's not feasable to put all of the information about a Building into the Room table, though many codes require information about the Building in order to classify the room. How would I count (or list/get details from) a room in the Rooms table, for use in an SQL statement about the Buildings table.If there are up to 5 rooms in the building, do at least 2 rooms contain a fire escape?

My Rooms table contains information about if the room has a fire escape, as well as references its parent Building ID. How would I query the rooms to count the Rooms within all buildings, and subsequently query all Buildings which have less than 2 rooms with fire escapes?I need it to return a list of the buildings which do not conform to this code.

Now this is literally my second day of programming/working with Access, but I've yet to find an answer dispite hours of searching.I think I can adapt it for the 100+ building codes/references I'll need to implement. It would be perfect to find an SQL-only way of doing this, without going into modules etc...

View Replies


ADVERTISEMENT

Queries :: Complicated Query (nested Subqueries) For A Trend Graph

Apr 17, 2014

Some essential background first. I have a Balances table which records balances by date. I also have an Issues table where problems are logged. There is a one-to-many relationship between Balances and Issues (i.e. each Balance can have multiple Issues). I also have a Comments table where updates for each Issue are recorded. There is again a one-to-many relationship between Issues and Comments (i.e. each Issue can have multiple Comments)

There are two key date fields in the Issues table :FlagDate (the date an Issue was flagged by a user for investigation)

ResolveDate (the date said investigation was brought to a conclusion)

There is also a date field in the Comments table :UpdatedWhen (the date any given comment was added)

So the basic flow is that an Issue gets flagged (FlagDate), then various comments are added (multiple UpdatedWhen's) and finally the Issue gets resolved (ResolveDate)

I need to incorporate a trend graph which will show the counts ofNew (i.e. new issues flagged as of each day) Cleared (i.e. issues resolved each day)

Updated (i.e. issues not yet resolved but updated each day)

Unchanged (i.e. issues not yet resolved and not updated each day)

Outstanding (i.e. all unresolved issues as of each day)

This is the SQL I've put together to get that table of information on which to base my chart :

Code:
SELECT [tblBalances].[BalanceDate] AS AsOfDate,
(SELECT COUNT([tblIssues].[IssueID])
FROM [tblIssues]
WHERE [tblIssues].[Flag] = True
AND [tblIssues].[FlagDate] = [tblBalances].[BalanceDate]) AS New,

[Code] .....

The subqueries for 'New', 'Cleared' and 'Outstanding' work perfectly; the resultant dataset gives me one record for each date in the Balance table and correctly counts the number of issues falling into each of those buckets.

The problem I have is with the 'Updated' bucket. If a flagged issue happens to be updated twice on the same day (which is perfectly acceptable), it counts this twice as well. I don't want this as I just want to know how many issues were updated on any given day - not how many updates there were.

I tried using COUNT(DISTINCT) in the 'Updated' subquery but it gives me a syntax error - on further research, I don't think it's possible to use the DISTINCT keyword in a COUNT subquery (at least not easily)

I also tried grouping by IssueID within that 'Updated' subquery but it still gives me the duplicate count within the same IssueID (and returns nulls rather than zeroes for those days where no updates occured)

I think I need to add a subquery within the subquery () to only return the latest comment as of the date in question - something along the lines of :

Code:
(SELECT TOP 1 [tblComments].[UpdatedWhen]
FROM [tblComments]
WHERE [tblComments].[IssueID] = [tblIssues].[IssueID]
AND DateValue([tblComments].[UpdatedWhen]) <= [tblBalances].[BalanceDate]
ORDER BY [tblComments].[UpdatedWhen] DESC) AS UpdatedWhen

But how to do this, nor if it is even feasible in Access to begin with.

View 2 Replies View Related

Queries :: Cannot Locate Source Of Table References

Feb 24, 2015

I have a database I took over, that generally uses linked tables to a MYSQL servers on another machine. The Access database uses a machine DSN to connect.

There are many queries that contain references to linked tables using another name. For example, the table is "service unit" but the queries are using "SU" as a reference. I cannot find any database object with that name SU. There are many such tables referenced like this - all uppercase letters, which is a common thing they all share.

Now, the server had a file integrity issue, and now the queries that contained the SU references will not work anymore. I created a linked table and called it SU and but the queries still won't work until I edit the queries, remove the old SU table, and add the new one in. So,

1. Where those table references could have come from, if it's not a linked table? Is there a hidden location on the server, or in the access database that stores another connection method?

2. Why won't simply adding a similarly named database object work the same way? Why must I re-edit all the queries?

View 1 Replies View Related

Queries :: Database Of References - Querying Two Values From Same Field

Aug 23, 2013

I'm quite new to Access and have inherited a database from a colleague. It is a database of references from which we have extracted pesticide active ingredient, pest species and crop species using forms. I am trying to create a query that will allow us to search and return unique active ingredient x pest x crop species combinations (but which will return all instances of this combination).

The complication is that the pest and crop species names are within the same field ('taxa'). They are distinguished by a label ('pest' or 'crop') in an associated field ('PestorPredator'), but a query using 'OR' will only return a crop OR pest, whilst a query using 'AND' will return no records (because something can't be a pest AND and crop).

I want to be able to create a table that shows the active ingredient, associated pest species AND the associated crop species each in separate columns. We have tried a couple of methods, including UNION and UNION ALL....

View 2 Replies View Related

Queries :: Numeric Expression May Contain Too Many Complicated Elements

Oct 31, 2014

Once again I am stuck. Basically I have a query as followed:Current: Sum(IIf([Run_date]-[dbo_GD-AgedDebtors]![BillDate]<=30,[dbo_GD-AgedDebtors]![Outstanding],0))I'm trying to show outstanding bills if the bill date is less than or equal to my date parameter. However, it keeps coming up "This expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables. (Error 3071)"

View 12 Replies View Related

Nested Queries And Forms

Jul 23, 2007

Hey,

I am working on my first access project (please be patient and try to explain like to a child). My problems however are past the basic level so please bear with me ....

I am working on a datbase which deals with laboratory data from patients which have different date stamps - ie. each record has a 'valid time' (time of blood drowing) a 'transaction time' (time of entry into the DB) and 'delete time' (deleted recordes are just given a date and not really deleted).

The idea is that the user should be able to watch the status of the DB at different past dates (ie what did the doctor know about a patient blood tests a month ago when he made the decision to give him a medication which eventually harmed his kideneys). The user should also be able to change values of records, delete records (which means to add a date to the deleted date field) and to add new records.

I want to do it all using one form.

Things I have done so far:
1. Query by form which locates a specific record (Main-Form & singleRecQuery)
2. A subform in Main-Form which displays the results of singleRecQuery (Single-subform). The query and subform aer updated by a macro once I enter all the data into main-form.
3. A qury by form derived from Main-Form which locates a range of values (Range-subfrom & Range-Query)

My problem spans both forms and queries (so I am posting in both forums):
1. I want to create an update query that will draw its data from Single-subform (the form which displays the results of singleRecQuery). I have created the qury without a problem but the fields in the form are locked for entering data (maybe because they are bound). Is there any way to enter data in such a form which is based on a query and then use the new data in another query ? (I tried allowing data entery in the forms properties but it deos't work).

2. I have tried to put a criterion in the queries on the "Delete Date" field so that the quries will not display the deleted records (I have tried "is null" "is empty" and "is missing") but when I run the query with these parameters I get no records back.

3. In the form I have a command buton which runs a macro that runs the qury and then update dthe subform. Is there a way to get this button to run different macros after different events in the form or do I have to add a button for every specific task I want.

4. As I have mentioned the Main-fom is supposed to run 3 differnt queries and display the results on the same form. I know how to make a subform invisable but is there a way to place all three result subforms in the same spot ?

Sorry it is so long
Thanks
EJ

View 1 Replies View Related

Problem With Nested Queries

Oct 11, 2004

Hi people ... here 's want i ve been trying to do for ages...

Subtract the result of this query

SELECT sum(tbl_order.sunoloaxias)
FROM tbl_order, tbl_client
WHERE tbl_client.arithmo = tbl_order.onoma_arithmo and tbl_client.arithmo=220;

from this query

SELECT sum(tbl_cash.amount) AS Eκφρ1
FROM tbl_client, tbl_cash
WHERE (tbl_client.arithmo)=220 And ((tbl_cash.pelatis)=tbl_client.arithmo);

I am trying to put it somehow in a nested query but i can t manage... Please send any answers that can help me
Thanks!!

View 3 Replies View Related

Queries :: How To Create Nested Query

Nov 14, 2013

I have done smoe baisc queries to sort, filter and report on data.How do I create a nested query where I don't repeat all the information across the query results line? Is there a way I can build a nested query to give all the SMCode codes associated with each appointment in one column separated by a coma?I have a table with appointments (APPTS):

RecID
ADate
ATime
Durantion
PVID
Desc
Case#

Then I have a table with Orders related to these appointments (ORDERS):

RecID
Case#
SMCode
SMDate

Here's my query:

SELECT DISTINCTROW Appts.RecID, Appts.ADate, Appts.ATime, Appts.Durantion, Appts.PVID, Appts.Desc, Orders.SMCode
FROM Appts INNER JOIN Orders ON Appts.[Case#] = Orders.[Case#];

My results look like this:

RecID ADate ATime Duration PVID Desc SMCode
RecID ADate ATime Duration PVID Desc SMCode
RecID ADate ATime Duration PVID Desc SMCode

I need my results to look like this:
RecID ADate ATime Duration PVID Desc SMCode,SMCode,SMCode...

View 3 Replies View Related

Queries :: Nested IIF - Not Getting Correct Value When Add Second Condition

Oct 24, 2013

I am using the IIf function as follows

Exp1:IIf(field A = "a string value",1,0) this returns the correct value.

However when I try to add a second condition using the IIf function, or use the And Or condition, I do not get the correct value.

I am trying to get a value of 1 in the Exp:Col when field B has a value that is different from field A.

What is the correct syntax? What am I missing??

View 13 Replies View Related

Need Help Fixing Sorting Problem Using Nested Queries

Dec 6, 2006

I have a set of two queries (which I'll call A and B, for convenience). Query A reads a table containing customer order numbers, a sequentially-assigned line number for each item requested by a customer on a particular order, and a part number associated with each order line. The line numbers are not integers, but run out to three decimals - so 1.000, 1.100, 1.150, 1.200, etc. would all be valid line numbers. All Query A does is to sort the table, with the primary (first) sort being order number, and with line number being the secondary (2nd) sort. Each record also contains a field equal to the integer value of the line number, so for lines 1.000, 1.100, 1.150, 1.200, this third value would always be 1; similarly, for lines 2.000, 2.100, and 2.200, the third value would be 2.

Query B uses query A as its source of input, and performs grouping (using the "Group By" function) so that query B's output displays only one record for each unique combination of customer order number and INTEGER line number; the part number displayed on each row of query B's output is supposed to be the part number on the first row of query A's output whose order number and integer line number correspond to each group in query B. (I am using the syntax of "First(Part Number)" in query B to report this.) This seems to be working most of the time, but not consistently; sometimes, for each unique order number / integer line number combination, Query B reports a part number from the wrong row of Query A. So, for example, order 12345, integer line 1, as reported from query B, may report the part number on line 1.300 from Query A, instead of line 1.000 from query A as intended.

Does anyone know a fix for this? I've got a team of anxious coworkers who are hoping for it.

Thanks a lot!

View 1 Replies View Related

Queries :: Getting Parenthesis Error In Nested IIF Query

Apr 15, 2015

I have different product groups and they can have one of 3 rental rates(5,4,3%) I have written a nested query but I keep getting parenthesis errors, the last one I got told me I must enclose iif functions in parentheses. I know its probably a small thing but I just cant see it. By the way the server is German so ; need to be used instead of ,.

IIf([view_India]![Sub_Group] In (1730;1810;2870);5;iif Left([view_India]![Sub_Group];2) In (01;02;21;24;29)
;5;iif([view_India]![Sub_Group] In (3310;3330;3340;3360);3;4))))

View 2 Replies View Related

Queries :: Nested IIF Statement In Date Calculation

Jul 30, 2015

I am trying to calculate the time between two dates where one date field might be blank or not. Where the field is blank I want to use the current date to perform the calculation. So far I have the following but I keep receiving an error message saying that the expression has a function with too many arguments. Is there a simpler solution to this?

IIF([LastOfEnd_Date] IS NULL,(DateDiff(w,[LastOfDischarge_Date],NOW()))/4, IIF(Not isnull([LastOfEnd_Date], Abs(DateDiff("w",[LastOfDischarge_Date].[LastOfEnd_Date]))/4

View 5 Replies View Related

Queries :: Make A Nested If Then Statement In A Query Field

Apr 27, 2014

I'm trying to make a nested if then statement in a query field, and I can't figure out why I can't get my formula to work:

Volume: IIf([MethodCode]="K",[total]*12.54*0.026873,IIf([MethodCode]="S",([length]*[width]*[depth])/2,IIf([MethodCode]="M" And [Location]="SH",[total]*5.08*0.026873,IIf([MethodCode]="M" And [Location]="C",[total]*18.58*0.026873," "))))

I keep getting the "data type mismatch in criteria expression" error. If I separate out all the individual if then statements individually, they work. But if I connect them all as a nested if then it doesn't work.

View 6 Replies View Related

Queries :: Multiple Nested IIF Statements - Output In One Field

Mar 25, 2013

I am trying to get the output of several nested IIF expressions to show in only one filed in the table created. The output needs to be captured in a table. I am staring with create table to get it to work before I go ahead and use the sql to update the original table (the table the data is from)

I can get each to run fine independently and the whole thing runs too, the issue is it wants to put each expression in a new column, thus it is forcing me to label the expression.

Can I change this to only output in one column or add some more sql to do so?

Here is the SQL (table and filed names have been changed to protect the innocent)

BTW, I cannot change the Table the data comes from, I am stuck with the single table structure (BOO).

************************************************** *************
SELECT TABLE1.ID,
IIf([TABLE1]![STAGE]="D",
IIf([TABLE1]![PROJ_ACTUAL_D_DATE] Is Not Null,"Tier 1",
IIf([TABLE1]![APPROVAL_D]="Y","Tier 2",

[Code] .....

View 1 Replies View Related

Queries :: Nested IIF - Returning Calculated Results In A Query

Oct 30, 2013

What is the best approach to returning calculated results in a query. I have been using nested IIf statements that include DateAdd but I think that I am at a point where there must be a better way.

I want my query to calculate a date based on:
1) A Type field from my table
2) A calculated date based on other query fields.

My query has the following fields:
[Type] [Action 1] [Projected Action 1] [Projected Action 1 Revised] [Action 2]

I want to create a calculated field for [Projected Action 2] that says:

If [Type] is "A" then
if [Action 2] Is NotNull, Null
if [Action 1] is NotNull, [Action 1] + 10 workdays
if [Projected Action 1 Revised] is NotNull, [Projected Action 1 Revised] + 10 workdays
if [Projected Action 1] is NotNull, [Projected Action 1] + 10 workdays

[Code] ....

I would like to keep using nested IIf but I keep running into problems and I thought that there is probably a better way.

View 7 Replies View Related

Queries :: Search Form That Fetches Records In Nested Tables?

May 25, 2014

I have three tables, tblPeople, tblAddresses and tblVehicles. I have a form called frmPeople that shows a single person record, and has subforms with the list of addresses and vehicles for that person (each record has several). I want to create a single search form with each of the fields in my tblPeople, tblAddresses and tblVehicle tables, and allow the user to type anything into any of the fields on the search form, and have the search form fetch records that match.

So far, I have the query built, and the tables all linked the right way (I think), and I have all the search fields coded. And it works GREAT... except for this one little issue: If I do a search, and I put "Smith" in the last name field, I will get several Smiths in my search result, one for each address and vehicle combination. In other words, if I have ONE Smith in the table, and two vehicles and two addresses for that Smith, the query results give me FOUR Smiths! One with Vehicle1 and Address1, one with Vehicle2 and Address1, one with Vehicle1 and Address2, and one with Vehicle2 and Address2.

What I would LIKE is to have ONE record in the query results, and that record shows me that one Smith. And if I then search for "Plymouth" in the VehicleType field, and I have Smith in the name field, I'll get ONE record, and it will be the one of Smith with his Plymouth (Vehicle2).

Here is how my query looks right now (this one ONLY has the last name and vehicle search function to save space), and this is the one that gives me multiple results (which I do NOT want, unless multiple PEOPLE match the search criteria):

Code:
SELECT DISTINCTROW tblPeople.LastName, tblPeople.FirstName, tblPeople.PersonID, tblAddresses.Address, tblVehicles.Vehicle, tblVehicles.Plate, tblVehicles.VehicleYear
FROM tblPeople LEFT JOIN tblAddresses ON tblPeople.PersonID = tblAddresses.PersonID
WHERE (((tblPeople.LastName) Like "*" & [NameField] & "*")
AND ((tblVehicles.Vehicle) Like "*" & [VehicleField]));

Did I write the query wrong?

View 4 Replies View Related

Queries :: Nested Query - Left Outer Join Not Returning All Records

Oct 1, 2014

I have a simple nested query that is not working as expected. My inner query returns 102 records but when I run with outer query I only get 96 records. Below is my query, I don't really want to pull the same fields from both tables but I was doing to test. The values that are missing are those that don't exist with the monthenddate 8/31/2014 - a left join should fix that but doesn't seem to be working ..

Code:

Select distinct a.entity, a.gl_account,a.profit_center,[Open Items_1].profit_center,[Open Items_1].gl_account,[Open Items_1].entity
from(
SELECT DISTINCT [Open Items].entity, [Open Items].gl_account, [Open Items].profit_center
FROM [Open Items]
)a
left outer JOIN [Open Items] AS [Open Items_1] ON
(a.profit_center = [Open Items_1].profit_center) AND (a.gl_account = [Open Items_1].gl_account) AND (a.entity = [Open Items_1].entity)
Where ([Open Items_1].MonthEndDate=#8/31/2014#)

View 1 Replies View Related

Question About "nested" Queries

Nov 15, 2006

I have two tables. I run a query matching certain fields between the tables and create a temp table. What I then want to do is take the same two tables, but matching against different fields, pull out from these tables everything that is not in the temp table.

Here are my table layouts:
TableA: TableB:
PartNumber PN
FSCM ATAPN
ManufactPN FSCM
SPN

I run this query:
SELECT TableA.PartNum, TableB.PN, TABLEB.ATAPN, TableA.Fscm, TableB.FSCM, TableA.ManufactPN, TableB.SPN INTO PartsTemp
FROM TableA LEFT JOIN TableB ON (TableA.ManufactPN = TableB.SPN) AND (TableA.Fscm = TableB.FSCM) AND (TableA.PartNum = TableB.PN)
WHERE (((TableB.PN) Is Not Null) AND ((TableB.ATAPN) Is Not Null) AND ((TableB.FSCM) Is Not Null)) OR (((TableB.PN)<>" ") AND ((TableB.ATAPN)<>" ") AND ((TableB.FSCM)<>" "));

After running that query, I next want to pull from Table A the same fields but only for those records that match PartNumber to ATAPN, FSCM to FSCM, ManufactPN to SPN and that don't have a part number in the PartsTem table I just created.

I'm going bonkers trying to wrap my head around this!!! Can anyone help out a frustrated geek? Thanks so much to those replying....this forum is great!!

View 1 Replies View Related

References

Feb 8, 2006

Hi

I have designed a couple of DB's using Access 2002 in Access 2000 format. While these all work perfectly in Access 2002 there a few users still using Access 2000 and are experiencing errors (specifically with Graph.exe which is 10.0 in 2002 and 9.0 in 2000 and also with the Calendar Control which is 10.0 in 2002 and 9.0 in 2000).

Is there a way to use the 2002 versions of these controls in 2000 or do I have to create the DB using the Access 2000 versions (in which case would I need to design the DB in Access 2000 instead of 2002).

Can anyone suggest anything or point me in the right direction.

Thanks

View 3 Replies View Related

References?

Jan 19, 2008

Anyone seen this before? The scenario is -
A distributed application on ten machines - all running the MDE in runtime.
All machines are running perfectly.
Minor changes made to the application and new MDE built.
After roll-out, six machines work perfectly with the new version. The remaining four run the application but experience the dreaded "#Name" in various places. Revert back to the previous version - and all run perfectly again.
Cannot be missing files - have not called for any and previous version works.
Cannot be broken references - six are running OK.
Cannot investigate on any of the machines because they are running MDEs.
??

View 14 Replies View Related

Setting References

Jun 22, 2005

Is it possible to set which VBA reference boxes are ticked each time a database is loaded?

A problem is created when a person amending the database to the person using it has different setups and so some of the references show as "missing" and so compile errors show on loading.

We are using Microsoft Access 97.

Any help most appreciated.

Dalien51

View 1 Replies View Related

Circular References

Jul 12, 2005

circular references caused by alias 'filed name' inquiry definition select list? What should i do

thanks

View 1 Replies View Related

References Problem?

Oct 18, 2005

Hi,

Iīm trying to run a db in a97 on an XP machine.

Iīm having problems with the datevalue function. Now I know the date function sometimes malfunctions due to a references problem, so I'm thinking maybe this is the same thing. However, there are no missing references.

I tried searching the forum, but couldnīt find the answer.

Fuga.

View 2 Replies View Related

Adding References Necessary?

May 9, 2007

Hi guys, ive been developing a database for someone. As some coding has been involved, I have added some references etc as I went along.

I'll be soon handing it over to them to use - will they have to add the references for the database to run on their comp? If so, is there more user friendly way of doing it than going into the VB bit etc?

Cheers...

View 3 Replies View Related

VBA References Missing

Feb 17, 2005

I have a database with a form. The form has quite a bit of code. This database is on a network. On some of the computers the Form will not open. When I go into Microsoft Visual Basic Tools References I am finding the following.

MISSING: Microsoft CDO 1.21 Library
MISSING: Microsfot ActiveX Data Objects 2.1 Library

Can anyone give me some advice on this issue?

Thanks for your help.

View 7 Replies View Related

List Box References

Dec 26, 2005

I have created a list box that acts as search criteria. It has 4 columns, SerialNo, Company, System, Processor. I need to reference these columns in VB with a sql statement that basically says:

Select * from SystemInfo
Where SerialNo = listboxSerialNo
and Company = listboxCompany
and System = listboxSystem
and Processor = listboxProcessor

My question is how do I refer to each of the columns in the listbox in my where statement? The listbox has the name, 'lstcriteria'. I can use just that in the reference and it will use the serialno only. How do I parse out each of the columns?

Thanks,

B

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved