Change Complex Query From IIf Statements

Mar 16, 2007

I had been using some SQL in Access with many IIf statements. I understand the equivalent in SQL is CASE, WHEN, END.
However, I'm really stuck with the following:
oh..ISNULL used to be Nz as well

IIf(ISNULL(ZI.InvoicesRaised,0)=0,0,IIf(IIf(ISNULL (ZA.TotalDebt,0)<>0,IIf(ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0)>0,30,(ISNULL(ZA.TotalDebt,0)*30)/ISNULL(ZI.InvoicesRaised,0)),0)>0,IIf(ISNULL(ZA.TotalDebt,0)<>0,IIf(ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0)>0,30,(ISNULL(ZA.TotalDebt,0)*30)/ISNULL(ZI.InvoicesRaised,0)),0),0))
+IIf(ISNULL(ZIMinus1.InvoicesRaised,0)=0,0,IIf(IIf (ISNULL(ZA.TotalDebt,0)<>0,IIf(ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0)-ISNULL(ZIMinus1.InvoicesRaised,0)>0,30,(((ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0))*30)/ISNULL(ZIMinus1.InvoicesRaised,0))),0)>0,IIf(ISNULL(ZA.TotalDebt,0)<>0,IIf(ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0)-ISNULL(ZIMinus1.InvoicesRaised,0)>0,30,(((ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0))*30)/ISNULL(ZIMinus1.InvoicesRaised,0))),0),0))
+IIf(ISNULL(ZIMinus2.InvoicesRaised,0)=0,0,IIf(IIf (ISNULL(ZA.TotalDebt,0)<>0,IIf(ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0)-ISNULL(ZIMinus1.InvoicesRaised,0)-ISNULL(ZIMinus2.InvoicesRaised,0)>0,30,(((ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0)-ISNULL(ZIMinus1.InvoicesRaised,0))*30)/(ISNULL(ZIMinus2.InvoicesRaised,0)))),0)>0,IIf(ISNULL(ZA.TotalDebt,0)<>0,IIf(ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0)-ISNULL(ZIMinus1.InvoicesRaised,0)-ISNULL(ZIMinus2.InvoicesRaised,0)>0,30,(((ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0)-ISNULL(ZIMinus1.InvoicesRaised,0))*30)/(ISNULL(ZIMinus2.InvoicesRaised,0)))),0),0))
+IIf(ISNULL(ZIMinus3.InvoicesRaised,0)=0,0,IIf(IIf (ISNULL(ZA.TotalDebt,0)<>0,IIf(ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0)-ISNULL(ZIMinus1.InvoicesRaised,0)-ISNULL(ZIMinus2.InvoicesRaised,0)-ISNULL(ZIMinus3.InvoicesRaised,0)>0,30,(((ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0)-ISNULL(ZIMinus1.InvoicesRaised,0)-ISNULL(ZIMinus2.InvoicesRaised,0))*30)/(ISNULL(ZIMinus3.InvoicesRaised,0)))),0)>0,IIf(ISNULL(ZA.TotalDebt,0)<>0,IIf(ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0)-ISNULL(ZIMinus1.InvoicesRaised,0)-ISNULL(ZIMinus2.InvoicesRaised,0)-ISNULL(ZIMinus3.InvoicesRaised,0)>0,30,(((ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0)-ISNULL(ZIMinus1.InvoicesRaised,0)-ISNULL(ZIMinus2.InvoicesRaised,0))*30)/(ISNULL(ZIMinus3.InvoicesRaised,0)))),0),0))
+IIf(ISNULL(ZIMinus4.InvoicesRaised,0)=0,0,IIf(IIf (ISNULL(ZA.TotalDebt,0)<>0,IIf(ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0)-ISNULL(ZIMinus1.InvoicesRaised,0)-ISNULL(ZIMinus2.InvoicesRaised,0)-ISNULL(ZIMinus3.InvoicesRaised,0)-ISNULL(ZIMinus4.InvoicesRaised,0)>0,30,(((ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0)-ISNULL(ZIMinus1.InvoicesRaised,0)-ISNULL(ZIMinus2.InvoicesRaised,0)-ISNULL(ZIMinus3.InvoicesRaised,0))*30)/(ISNULL(ZIMinus4.InvoicesRaised,0)))),0)>0,IIf(ISNULL(ZA.TotalDebt,0)<>0,IIf(ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0)-ISNULL(ZIMinus1.InvoicesRaised,0)-ISNULL(ZIMinus2.InvoicesRaised,0)-ISNULL(ZIMinus3.InvoicesRaised,0)-ISNULL(ZIMinus4.InvoicesRaised,0)>0,30,(((ISNULL(ZA.TotalDebt,0)-ISNULL(ZI.InvoicesRaised,0)-ISNULL(ZIMinus1.InvoicesRaised,0)-ISNULL(ZIMinus2.InvoicesRaised,0)-ISNULL(ZIMinus3.InvoicesRaised,0))*30)/(ISNULL(ZIMinus4.InvoicesRaised,0)))),0),0)) AS DD

Do I have to put in some seriously heavyily nested CASE statements or are there some other ways round this?

View Replies


ADVERTISEMENT

If-Then Statements In "On Change" Event

May 1, 2006

I have a database with two forms. The Products form with the account line item subform embedded in it.

In the Accounts Credited field of the Products form, I have a VB statement (below) under the "on change" event. It forces two fields in the accounts table to be changed. The Accounts Credited field is a combo box with a value list of "savings"; "Checking"; "PayPal"; etc. Every time you change that value, it should force a change in the AccountName field's text property to match it, and it should also change the AccountID field's value to the corresponding number.

The AccountName and AccountID fields are a part of the Accounts Table. AccountID links the Accounts Table and the AccountLineItem table. However I can't get the VB Code to run when the different "accounts credited" options are selected. It should change the account ID value in the subform.

It's a class project and the professor has told us that everyone in the class receive an "incomplete" for the course unless the database works by wednesday. She has not given us the tools to do what we need to do though, any help would be greatly appreciated.

Thanks!

code for "on Change" event:

Private Sub AccountCredited_Change()

If (Field_Accounts!AccountName.Text = "Savings") Then
Field_Accounts!AccountID.Value = 1
End If

If (Field_AccountName.Text = "Checking") Then
Field_AccountID.Value = 2
End If

If (Field_AccountName.Text = "PayPal") Then
Field_AccountID.Value = 3
End If

If (Field_AccountName.Text = "Building") Then
Field_AccountID.Value = 4
End If

If (Field_AccountName.Text = "Animal Control") Then
Field_AccountID.Value = 5
End If
End Sub

View 1 Replies View Related

QUERY IIf Statements In Criteria

Sep 7, 2005

:confused:
Hi I need help inserting IIF statements as criterias in my query.

Here's the query I have created from a table called XML_EXPORT which consists of a list of ORGANIZATIONS with various fields. What I'm trying to do is display:
-the name of the EXEC_NAME_1 (primary executive's name)
-the ADDRESS
-the CITY
-the POSTAL_CODE
-the PROVINCE
-the PUBLICATION
-the ORG_LEVEL_1 (the organization's main name)
-the ORG_LEVEL_2 (the organization's departments 2 to 5)
-the ORG_LEVEL_3
-the ORG_LEVEL_4
-the ORG_LEVEL_5

Now not every record contains data in ORG_LEVEL_2 to ORG_LEVEL_5 so we want to display only ORG_LEVEL_1 and the last ORG_LEVEL that is not blank.

i.e. If a record has ORG_LEVEL_4 and ORG_LEVEL_5 blank then we want to only display: ORG_LEVEL_1 and ORG_LEVEL_3 (even though there is something in ORG_LEVEL_2)

Here's my query:

------------------------------------------
SELECT XML_EXPORT.EXEC_NAME_1, XML_EXPORT.ADDRESS, XML_EXPORT.CITY, XML_EXPORT.POSTAL_CODE, XML_EXPORT.PROVINCE, XML_EXPORT.PUBLICATION, XML_EXPORT.ORG_LEVEL_1, XML_EXPORT.ORG_LEVEL_2, XML_EXPORT.ORG_LEVEL_3, XML_EXPORT.ORG_LEVEL_4, XML_EXPORT.ORG_LEVEL_5
FROM XML_EXPORT
WHERE (((XML_EXPORT.ADDRESS) Is Not Null));
------------------------------------------

Can anyone show me how the Iif statement syntax would be ?
Allan

View 2 Replies View Related

Update Query. How Many Iif Statements Are Allowed?

Jan 30, 2008

Hi,

I am going to be creating a iif statement update qery, to update a column on dates, E.g. would be....

IIf([FinMonth] between 01/01/2008 and 31/01/2008,1)iif([FinMonth] between 01/02/2008 and 30/02/2008,2)iif(etc etc

2 questions??

1) Is 12 nested iif's statements are allowed within one IIF statement?
2) iS THERE AN EASIER WAY TO DO THIS??

Hope this explains enough.

Thanks

View 14 Replies View Related

Query Support Multiple SQL Statements

Feb 17, 2008

Hi everyone,

I am writing a query that is master-detail in principal. But need other data from other 2 tables. I wonder if I can construct the query so that it contains the result set of more than one SQL statement. Thank you for your kindly help.


Gary AU

View 1 Replies View Related

Queries :: Multiple If Then Statements In Query

Jan 30, 2015

I have a query that I just can't figure out. We are a facility that works on rail cars. We have over 200 cars in house at the moment and the database has a daily production report in it with the status of all of the cars.

I need a query that will pull out the "AAAA" and "XXXX" cars from the list only IF the cleaning field or the mechanical inspection or BOTH fields are blank.

View 6 Replies View Related

Queries :: Combining SQL Statements In A Query

Sep 16, 2014

I have 2 queries serving useful routines, one to filter out duplicate addresses for a mailing label routine, the second to convert tick boxes into Y/N answers for a Tab Delimited Text file export.can I combine the 2 SQL statements in the 2nd query without amending them in any way.

The SQL statements are;

FROM [Mail List] AS a
GROUP BY a.[Member ID], a.[Address 1], a.[Member Name], a.[Address 2], a.Town, a.PostCode, a.[e-News List], a.[e-Mail List], CStr([a].[Member ID])+[a].[Address 1]
HAVING (((a.[e-News List])=False) AND ((CStr([a].[Member ID])+[a].[Address 1])=(Select cStr(Min(b.[Member ID])) + b.[Address 1]
From [Mail List] as b
Where b.[Address 1] = a.[Address 1]
Group By [Address 1])));

[code]...

View 7 Replies View Related

Queries :: If Statements To Set Parameters In A Query?

Jul 25, 2013

im working in MS Access 2007.what im trying to do is have a query run specific parameters if a check box is selected. So if the check box is selected than the query filters the "Tranche" column so that the only records that shown are records that have the "Tranche" coloumn = 1.

I know this can be done either in vba code or in the criteria section of a query but i dont know that appropriete language for either.

In vba code i was able to get this far. But..... i dont know how to call the criteria line from a query?

This is my very simple unfinished code.

My query is called [Tranch Query] and the column i want to filter with is call [Tranche]. The check box is called [Check0].

Private Sub Check0_AfterUpdate()
If Check0 = True Then
'How do i set the query criteria?????
End Sub

View 8 Replies View Related

Query Is Too Complex

Aug 4, 2007

Hello ,
I had incountered with a huge problem in my project and I need your help guys.
I have a huge table contains alot of data about many people- I wanted the data will be checked and sent to a query.
Here is an example for a little project beacuse I couldn't have the big one.
(This example works fine)
My big project is pretty the same but after I try to get the query out I get an error that the query is too complex....(It's really too big when you have 20texts to be checked with 9000 fields)
If you check the query fields you may see how the OR is getting separted and because every text has OR statement everything is hanged by everything.
Someone told me that I can't use query options and mannge it and I should use VB SELECT option - but I can't make it work too.
So I can't show you the real example at all beacsue I can't have it to my computer and It will take alot of time to have 9000 different cells ;
SO if someone knows what I am talking about and ever encoutered it , I would be really thankful !
(Also - You may see some problems with the OR ("") but I mannged it to work with the BIG project so it doesn't matter)
I don't want you to focus the conditions but just the problem itself ...." the query is too complex"...

View 6 Replies View Related

Help, Query To Complex???? But How?

May 25, 2005

Hi,

This one is a pain in the but. I tried everything, but why would it just won't work. It always says the query is to complex. Have included the database, anyone a solution?

Thanks

View 2 Replies View Related

Complex Query

Sep 16, 2005

I need to perform a query on a database (not designed by me) that is not normalized. In fact it is only one table with numerous fields (many of them Date/Time). I need to query the table based on the date fields only.

Basically the table is used to track when specific functions are completed to determine the time required to perform the individual tasks (accuracy to one day is acceptable) and find the ones which are falling behind. Since several individuals are required to complete each project each step has an average value (based on historical data.)

The following is a short narrative:

1. Step 1 is scheduled for 1/5/05 and the task is not started untill 1/7/05. This is not acceptable. There is a 1 day window. I need to flag this record (via report) if the start date exceeds the schedule date by more than 1 day. If a start date has been entered this record does not need flagged (regardless of the alloted time).

2. Step 2 is based on the amount of time alloted to complete the task once started. If the task takes more than 2 days the project needs to be included in the query for the report. As above, if the date is entered the record is not needed since there is no need to try to determine the when the project will start.

3. Step 3 measures the number of days from the project completion untill the product is sent to the central office. If the time exceeds 2 days the record needs to be included in the dataset. Again, once a date is entered in the received field there is no need to include the record.

There are a couple more steps but they follow the same criteria as the first three.

I have not been able to figure out how to get these requirements entered into the query design view.

View 3 Replies View Related

Complex Query (at Least For Me It Is)

Sep 19, 2005

This is the table structure that I use:

CAR TABLE
==========
Car_Id
Car_Tag_Number


CLIENT TABLE
============
Client_Id
Client_Name


CLIENT-CAR TABLE
=================
Car_Client_Id
Car_Id
Client _Id


ORDER TABLE
============
Order_Id
Car_Client_Id
Order_Date
Payment_Date
Payment_Amount

ORDER-DETAILS TABLE
=====================
Order_Detail_Line_Number
Order_Id
Item_Id
Order_Detail_Price
Order_Detail_Qty


The query I'm trying to get is: Who owes me money for the service and How much.

Each car had several treatments in the past and some have missed a payment or I didn't notice and just issued a new order.

I need a query that runs through the entire database, does a summary of all the amount owed to me per Car, and then deducts the total payments made per Car. If the balance is > than Zero,. Show me that car and the bottom line amount.

Please let me know if you can help with this.

-Alon
alon@wsco.com

View 1 Replies View Related

Complex Query

Dec 14, 2005

Hi guys, long time surfer, first time poster here :)

We use a prehistoric Process Plant design software package, and it stores all its information in Oracle 8i.

A report I need to pull takes data from a stack of tables, each with a unique number.

PDTABLE_113 contains a list of models, each model having a unique PARTITION_NO.

Every PARTITION_NO entry has a matching table called PDTABLE_21_XXXX where XXXX is the PARTITION_NO of the model. Each PDTABLE_21_XXXX has a row for every piece of equipment in the relevant model.

PDTABLE_21, for argument sake, has the columns EQUIPMENT_ID, EQUIPMENT_DESCRIPTION, and EQUIPMENT_STATUS.

Is there some way to query the database so I get something that looks kinda like this:

MODEL_NO=====PARTITION_NO=====EQUIPMENT_ID===etc..
A1A1M01======1516=============XYZ-110-A=====etc..
A1A1M01======1516=============XYZ-111-A=====etc..
A1A2M01======1517=============ABC-122-A=====etc..
A1A2M01======1517=============ABC-123-A=====etc..

View 3 Replies View Related

Complex Query Help Please

Aug 31, 2006

Hello, this is kinda complicated to explain so Ill try to break it down.

I have a table with the following sample data

SerialNumber DateReceived Measured Level
0000-0024 25/08/2006 11:31 84
0000-0024 25/08/2006 12:59 84
0000-0024 25/08/2006 15:05 84
0000-0021 25/08/2006 10:08 32
0000-0021 25/08/2006 17:19 32
0000-0024 24/08/2006 09:45 88
0000-0024 24/08/2006 16:06 88
0000-0021 24/08/2006 13:09 36

etc

this shows that I can have multiple entries in a day for a particular serial number.

I need to select ONLY ONE serial number and corresponding data for each day (or week).

I tried to format the date to remove the time and then select the distinct date (so 1 record a day for each serial was displayed), this worked.
BUT
I could not link it successfully to other tables because I had to format the corresponding match date to avoid a type mismatch thus invalidating what i was doing by selecting the distinct record.

Here is the original query i was using that selected a range of dates (which included multiple dates in a single day with a single serial).


SELECT TBLRemoteUnitInfo.TankSize, TBLRemoteUnitInfo.TankName, * FROM TBLRemoteUnitRequests, TBLRemoteUnitInfo WHERE (TBLRemoteUnitRequests.RemoteFeildUnitID = TBLRemoteUnitInfo.RemoteFeildUnitID) AND (TBLRemoteUnitRequests.SerialNumber=:SerialNumber) AND (TBLRemoteUnitRequests.DateReceived BETWEEN :Datestart AND :Dateend)
ORDER BY TBLRemoteUnitRequests.UnitRequestID';

how can i take a sample of the range of dates (ie 1 a day/week or month), i assume i need to create a filtered table via query first then query that table.

Its killing me!

if i am being unclear please let me know and ill try to clarify

Dan

View 3 Replies View Related

Complex Query, Any Help??

Feb 6, 2007

Hi

I have come to a dead end with my query. Any help would be really appreciated.

I have a query which i have written:

SELECT TblBurnleyWwTw.MetricID
FROM TblBurnleyWwTw
WHERE (((TblBurnleyWwTw.[Data Source])="OMS")) OR (((TblBurnleyWwTw.TAGFunction)="CHP"))
GROUP BY TblBurnleyWwTw.MetricID, TblBurnleyWwTw.[Metric Required], TblBurnleyWwTw.CALCULATIONS, TblBurnleyWwTw.PIPointSource, TblBurnleyWwTw.PILoc1, TblBurnleyWwTw.[High Level KPI]
HAVING (((TblBurnleyWwTw.MetricID) Like "130*") AND ((TblBurnleyWwTw.[Metric Required])="-1") AND ((TblBurnleyWwTw.PIPointSource)<>"L"));

This retreives all codes relating to what i want. The problem is, I need this data to try and match within another column of calculations E.g. Data retreived from query I have may be 13001, 13002, 13003. What I would like to do with this data is to lookup in a calculations column if any of the above data matches to bring back the metric ID which is realted to it?

Hope i have stated this clearly enough for anyone to understand???

As i say any help or recommednations for a solution would be really appreciated

Andrew

View 6 Replies View Related

Says Query Is Too Complex.

Mar 29, 2007

SELECT [UK Table].[Business Name], [UK Table].[Business Type], [UK Table].Address, [UK Table].City, [UK Table].Country, [UK Table].[Telephone Number], [UK Table].[Website Address], [UK Table].[Email Address]
FROM [UK Table]
WHERE ((([UK Table].[Business Name]) Like [Forms]![frmNz]![txtBusinessName] & '*' Or [Forms]![frmNz]![txtBusinessName] Is Null) AND (([UK Table].[Business Type]) Like [Forms]![frmNz]![txtBusinessType] & '*' Or [Forms]![frmNz]![txtBusinessType] Is Null) AND (([UK Table].Address) Like [Forms]![frmNz]![txtAddress] & '*' Or [Forms]![frmNz]![txtAddress] Is Null) AND (([UK Table].City) Like [Forms]![frmNz]![txtCity] & '*' Or [Forms]![frmNz]![txtCity] Is Null) AND (([UK Table].Country) Like [Forms]![frmNz]![txtCountry] & '*' Or [Forms]![frmNz]![txtCountry] Is Null) AND (([UK Table].[Telephone Number]) Like [Forms]![frmNz]![txtTelephoneNumber] & '*' Or [Forms]![frmNz]![txtTelephoneNumber] Is Null) AND (([UK Table].[Website Address]) Like [Forms]![frmNz]![txtWebsiteAddress] & '*' Or [Forms]![frmNz]![txtWebsiteAddress] Is Null) AND (([UK Table].[Email Address]) Like [Forms]![frmNz]![txtEmailAddress] & '*' Or [Forms]![frmNz]![txtEmailAddress] Is Null));

What is wrong? I have attached the database. The form frmNz is what I want to work. I should be able to enter company information into at least one field, allowing me to retrieve the specific company data from the UK Table in the subform.

Gurdip.

View 12 Replies View Related

Complex Query

Jun 28, 2007

I have three tables called, Clients basic details, Episode and Modality. There are some 56 fields in these tables. Once a month I run a query on these tables. The data is then uploaded to another site via the internet.
I have now been asked to collect data into another table called TOPS which has some 23 new fields in it.
The problem I have is, they want none of the TOPS data to be on the same line as the Modality Data. For instance, there are 79 fields in the query which must conform to certain parameters before the data can successfully uploaded, the query must show lines of data for all the 79 fields, but if any line has TOPS information the line cannot have Modality information in it and vice versa. I think some of the data that would be collected will be duplicate, i.e. from the episode and clients basic details tables.
The query must show all 79 field headings. Any line of Data in the query result that has data from the Modality table and data from the TOPS table can only show the returned data from one of these tables, the values from the other table must be left blank and vice versa.
For Instance say From the clients details table we show the clients name, from the episode table we show the number of children he has, from the Modality table we show he has structured intervention, we then must show blank records from the TOPS table.
Then on another line the query must pick up the data from the TOPS table, episode table and clients basic details table and leave the Modality table fields blank.
A lot of the info from the Clients and episode table will be duplicated but on the different lines.

Any Help would be greatly appreciated
Barry

View 2 Replies View Related

Query Is Too Complex

Jul 24, 2007

I am trying to create ranges in data in order to create a graph. I have the following IIf statement that access says is too complex and also Im getting an error saying that it is too long to edit so does anyone have any ideas how to do this with out these problems. I need to get to $25000 $30000 in increments of $1000.

IIf([Actual$/Mile]<1000,"$0 to $1000",IIf([Actual$/Mile]>=1000 AND [Actual$/Mile]<2000,"$1000 to $2000",IIf([Actual$/Mile]>=2000 AND [Actual$/Mile]<3000,"$2000 to $3000",IIf([Actual$/Mile]>=3000 AND [Actual$/Mile]<4000,"$3000 to $4000",IIf([Actual$/Mile]>=4000 AND [Actual$/Mile]<5000,"$4000 to $5000",IIf([Actual$/Mile]>=5000 AND [Actual$/Mile]<6000,"$5000 to $6000",IIf([Actual$/Mile]>=6000 AND [Actual$/Mile]<7000,"$6000 to $7000",IIf([Actual$/Mile]>=7000 AND [Actual$/Mile]<8000,"$7000 to $8000",IIf([Actual$/Mile]>=8000 AND [Actual$/Mile]<9000,"$8000 to $9000",IIf([Actual$/Mile]>=9000 AND [Actual$/Mile]<10000,"$9000 to $10000",IIf([Actual$/Mile]>=11000 AND [Actual$/Mile]<12000,"$11000 to $12000",IIf([Actual$/Mile]>=12000 AND [Actual$/Mile]<13000,"$12000 to $13000",IIf([Actual$/Mile]>=12000 AND [Actual$/Mile]<13000,"$12000 to $13000",IIf([Actual$/Mile]>=13000 AND [Actual$/Mile]<14000,"$13000 to $14000",0
))))))))))))))

View 14 Replies View Related

Complex Query??

Oct 10, 2007

Hello everyone!
i hope someone can help me with either:
1. writing a query to get the results needed (will explain below)
2. write VBA to be used in query to get the results needed
3. or change table(s) to be able to obtain the data in all areas to get the results needed.


The result needed:
How can I get the result of ONLY when there's an exact match of the combinations and not all combinations of the matches?

I have a GuitarOptionDetails and it's linked (LEFT OUT JOIN) to a ProgramCodes.
so the basic result here is displaying correctly. it's showing everything in my GuitarOptionDetails and only where there's matches from the ProgramCodes. Linked on Guitar and Option as these fields are in both sides. The ProgramCodes has the "Code" for the guitar and guitar / option combinations.

Issue, and why I'm seeking help ... i need to somehow change that so it will only show the set of results where the combinations matches.

example
here's the "raw" data from ProgramCodes table

GuitarOptionCodeComboID
AE185185RR1
AE185186RHT1
AE185187RT1
AE18538185RR2
AE18538186RHT2
AE18538187RT382
AE185BB185RR3
AE185BB186RHT3
AE185BB188RT-B3
AE18538185RR4
AE18538186RHT4
AE18538188RT38B4
AE185BB185RR4
AE185BB186RHT4
AE185BB188RT38B4


GuitarOptionDetails is showing the Codes for ComboID's 2, 3, and 4 because an invoice for AE185 has BOTH 38 and BB. Again, the basic LEFT OUTER JOIN query is showing all the Codes for AE185 where there's 38 or BB.

But instead, i need the result to show only the ComboID 4 Codes and not to repeat the same Codes for the ComboID 4 Codes.


I truly hope I made sense and there's a solution for this. I have no idea how to look it up to see if there's any previous posting for this or something like this, etc ...


Thank you in advance!

View 14 Replies View Related

Update Query With Multiple Part If Statements

Aug 13, 2014

I have a table where I have 5 columns, (BatteryL1, BatteryL2, BatteryR1, BatteryR2 and BatterySize).I want to update BatterySize, with a value if any one of the above listed columns contains a specific value using something like 'LIKE' in the query.

For example:
UPDATE Customers
SET BatterySize=13
WHERE BatteryL1 LIKE '%13%'

[code]...

View 3 Replies View Related

Query Is Too Complex... On Report, But Query Runs Fine

Oct 18, 2005

Hi...

I have a query that when I run it normally (just click on it) then it runs fine. (It is a union query, getting it's data from 8 other queries (who has their dependancies)

But when I want to run a report from it, Access gives me an error saying "query is too complex".

I am flattered, but I would prefer access to work than say I write stuff that is too complex for it. :cool:

Any ideas?

I am confused by the fact that it runs when I double click the query, but the report bugs it out.

-Reenen

View 1 Replies View Related

Complex Query Sort

Jul 19, 2005

I need to sort my query in a rather complicated way, and haven't been able to get the examples I've found on here to work.

I have the following fields
[Category]
[Name]
[Page]

Here is what I need.
Where [Category] = "Table of Contents"
Sort by [Name], Then by [Page] Descending
Else
Sort by [Name], Then by [Page] Ascending

All records will be queried at the same time, so "Table of Contents" categories will be included in the same query as other records, but need a different sort order. I know this is stupid, but leave it to government to impose some nonsensical rule on you.

Is there a way to do this?
Thanks,
Doc

View 4 Replies View Related

Complex Date Query (or Is It)

Nov 10, 2005

Hi All

I'm hoping somebody out there might be able to point me in the right direction for solving this problem.

Im developing a hire stock control database and have a table that contains all the order reference numbers and in and out dates.

What i am trying to do is structure a query that searches for all instances of a shipping out/in date that fall within date values already stored in the source table.

e.g. Table values

Out .................In
1/11/05............10/11/05
3/11/05............5/11/05

Query Values

Out..................In
25/10/05............2/11/05

In this instance only the first record in the table should be found.
Many thanks for help in advance

Simon

View 3 Replies View Related

Complex Query On 3 Tables

Feb 15, 2006

I need to create a query based on the following 3 tables.

table PA0001 has the following entries (first line is the header data)

EmployeeNumber - ContractType0001
1234 - 1
1235 - 2
1236 - 1
1237 - 1
1238 - 2
1239 - 3
1240 - 2

PA0016 has the following entries:

EmployeeNumber - ContractType0016
1234 - 11
1235 - 12
1236 - 13
1237 - 11
1238 - 11
1239 - 13
1240 - 12

There is a mapping table called, lets say tblMappingTable which has the following fields:

Contract0001 - Contract0016
1 - 11
2 - 12
3 - 13

Basically I need to write a query which interrogates all the records PA0001 checks the mapping table and gives me all the records in PA0016 which do not have the expected mapping result.

So based on the above data I would expect it to return only the non-matched data, which will be:

EmployeeNumber - ContractType0001 - ContractType0016
1236 - 1 - 13
1238 - 2 - 11

I would probably need to do another query which does the exact same thing but the other way around. It would need to interrogate all the records from PA0016 and using the mapping table check the records in PA0001. In my example above I would get the exact same result, but I suspect with large amounts of data, I would get different results, especially if the number of records were not the same in both tables.

I suspect I would need to write some SQL code or VB code to extract the above.

If one of you kind folk could give me some basic pointers that would be great.

Thanks,

Evan

View 2 Replies View Related

Query Is Too Complex In Ms Acess 2.0

Jun 13, 2006

Hi ,

I have two queries . one to list the data for the current month and the for the pervious month which I used to get a union query. From the union query I created another query which I had put in the report_open as a query def.

It works perfectly well on small databases upto 50 mb but when tested with 70mb databases ,report tabkes 30 minutes to execute and also throws the error"query is too complex"

please advise how I can avoid this error and also speed up the report.
Thanks in advance.

the code under report_open looks like this

Dim MyWorkspace As WorkSpace, MyDB As Database, MyQuery As QueryDef
Dim MySet As Recordset
Dim psSql As String
Dim inputno As Integer

Set MyWorkspace = DBEngine.Workspaces(0)
Set MyDB = MyWorkspace.Databases(0)
inputno = store

psSql = "SELECT DISTINCTROW QryRepCMISUnionLargeMovements.Customer_Name,"
psSql = psSql & " QryRepCMISUnionLargeMovements.CUST_ID, QryRepCMISUnionLargeMovements.CRG_CODE,"
psSql = psSql & " QryRepCMISUnionLargeMovements.CurrLimits1, QryRepCMISUnionLargeMovements.PrevLimits1,"
psSql = psSql & " QryRepCMISUnionLargeMovements.Lim1Var AS Lim1Var11, QryRepCMISUnionLargeMovements.CurrLimits2,"
psSql = psSql & " QryRepCMISUnionLargeMovements.PrevLimits2, QryRepCMISUnionLargeMovements.Lim2Var AS Lim2Var11,"
psSql = psSql & " QryRepCMISUnionLargeMovements.Input_Section"
psSql = psSql & " FROM QryRepCMISUnionLargeMovements;"


MyDB.QueryDefs("a").SQL = psSql
Set MyQuery = MyDB.QueryDefs("a")

View 3 Replies View Related

Complex Calculated Query?

Jun 20, 2006

Hi everyone,

OK this is a pretty big question, but here it is....

I am not quite sure that a query is the best thing to use in this case, but I think it might be possible. Here is what I need to do: I have a table with information about oil well production. In this table the production of each oil well is recorded once a month (Barels of Oil, Water, and amount of Gas produced, and the number of days that the well produced in that month). This table ranges in dates from 1986 to 2006 and has records every month in that time span. You can see a sample of how the design of this table is in the attachment (Table: [Well Data]).

What I need to do is have a query look at this main table and create another table with some calculated fields. This new table will have only 1 record for each well. You can see a sample of the table that needs to be created in the attachment (Table: [New Table]). In this table, the first 8 columns are not calculated at all, they are just recorded from the main table. The next columns are calculated. As you can see in the attached preview, the query needs to find the first 180 days (6 months) that a well is producing and sum the oil, gas, and water in that time. It also has to do this for the first 365 days (12 months). Then it has to record the earliest date that a well has in the [Well Start Date] column and the latest date a well has [Well End Date]. And last, it has to determine how many total days the well was producing (Subtract [Well End Date] - [Well Start Date]).

I know this is a lot to comprehend, so please ask questions if you don't understand me. I really appreciate your help!!

Thanks,
Chris

View 1 Replies View Related







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