473,654 Members | 3,109 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combining the following queries without getting query too complex error

I have created the following interest to calculate the interest for
the following currency pairs. I have tried to combine them in macros
using conditions but the next query that is run in the macro ends up
deleting the previous interest value that has been generated by the
query. For example if query 1 is run on the table with currency pair
USD/CHF then the interest will be updated without any problem but if
there is another entry in the table with another currency pair for
example EUR/JPY which is calculated say in query two then the interest
of USD/CHF which has been calculated previously will be deleted. I
think the only way to solve this would be to combine the queries
instead of seperating them using macro conditions. Please tell me how
I would appreciate it alot.

This is query1:
UPDATE [Spot Open Positions], [Sell Rate], [Buy Rate] SET [Spot Open
Positions].[INTEREST WED] = IIf([Spot Open Positions].[Sell]>0 And
[Spot Open Positions].[ITEM]='USD/CHF' AND [Spot Open
Positions].[DAY]=4,([Sell Rate].[USD/CHF]*[Spot Open
Positions].[Sell]*100000*3)/36000,IIf([Spot Open Positions].[Sell]>0
And [Spot Open Positions].[ITEM]='EUR/USD' AND [Spot Open
Positions].[DAY]=4,([Sell Rate].[EUR/USD]*[Spot Open
Positions].[Sell]*100000*3)/36000,IIf([Spot Open Positions].[Sell]>0
And [Spot Open Positions].[ITEM]='USD/JPY'AND [Spot Open
Positions].[DAY]=4,([Sell Rate].[USD/JPY]*[Spot Open
Positions].[Sell]*100000*3)/36000,IIf([Spot Open Positions].[Sell]>0
And [Spot Open Positions].[ITEM]='GBP/USD' AND [Spot Open
Positions].[DAY]=4,([Sell Rate].[GBP/USD]*[Spot Open
Positions].[Sell]*100000*3)/36000,IIf([Spot Open Positions].[Sell]>0
And [Spot Open Positions].[ITEM]='AUD/USD' AND [Spot Open
Positions].[DAY]=4,([Sell Rate].[AUD/USD]*[Spot Open
Positions].[Sell]*100000*3)/36000,IIf([Spot Open Positions].[Sell]>0
And [Spot Open Positions].[ITEM]='XAU/USD' AND [Spot Open
Positions].[DAY]=4,([Sell Rate].[XAU/USD]*[Spot Open
Positions].[Sell]*100000)/36000*3,IIf([Spot Open Positions].[Buy]>0
And [Spot Open Positions].[ITEM]='USD/CHF' AND [Spot Open
Positions].[DAY]=4,([Buy Rate].[USD/CHF]*[Spot Open
Positions].[Buy]*100000*3)/36000,IIf([Spot Open Positions].[Buy]>0 And
[Spot Open Positions].[ITEM]='EUR/USD' AND [Spot Open
Positions].[DAY]=4,([Buy Rate].[EUR/USD]*[Spot Open
Positions].[Buy]*100000*3)/36000,IIf([Spot Open Positions].[Buy]>0 And
[Spot Open Positions].[ITEM]='USD/JPY' AND [Spot Open
Positions].[DAY]=4,([Buy Rate].[USD/JPY]*[Spot Open
Positions].[Buy]*100000*3)/36000,IIf([Spot Open Positions].[Buy]>0 And
[Spot Open Positions].[ITEM]='GBP/USD' AND [Spot Open
Positions].[DAY]=4,([Buy Rate].[GBP/USD]*[Spot Open
Positions].[Buy]*100000*3)/36000,IIf([Spot Open Positions].[Buy]>0 And
[Spot Open Positions].[ITEM]='AUD/USD' AND [Spot Open
Positions].[DAY]=4,([Buy Rate].[AUD/USD]*[Spot Open
Positions].[Buy]*100000*3)/36000,IIf([Spot Open Positions].[Buy]>0 And
[Spot Open Positions].[ITEM]='XAU/USD' AND [Spot Open
Positions].[DAY]=4,([Buy Rate].[XAU/USD]*[Spot Open
Positions].[Buy]*100000*3)/36000)))))))))) ));

This is query2:
UPDATE [Spot Open Positions], [Sell Rate], [Buy Rate] SET [Spot Open
Positions].INTEREST = IIf([Spot Open Positions].[Buy]>0 And [Spot Open
Positions].[ITEM]='EUR/JPY' AND NOT [Spot Open
Positions].[DAY]=4,((([Buy Rate].[EUR/USD]+[Buy
Rate].[USD/JPY])/2)*[Spot Open
Positions].[Buy]*100000)/36000,IIf([Spot Open Positions].[Sell]>0 And
[Spot Open Positions].[ITEM]='EUR/JPY' AND NOT [Spot Open
Positions].[DAY]=4,((([Sell Rate].[EUR/USD]+[Sell
Rate].[USD/JPY])/2)*[Spot Open Positions].[Sell]*100000)/36000,
IIf([Spot Open Positions].[Buy]>0 And [Spot Open
Positions].[ITEM]='GBP/JPY' AND NOT [Spot Open
Positions].[DAY]=4,((([Buy Rate].[GBP/USD]+[Buy
Rate].[USD/JPY])/2)*[Spot Open
Positions].[Buy]*100000)/36000,IIf([Spot Open Positions].[Sell]>0 And
[Spot Open Positions].[ITEM]='GBP/JPY' AND NOT [Spot Open
Positions].[DAY]=4,((([Sell Rate].[GBP/USD]+[Sell
Rate].[USD/JPY])/2)*[Spot Open
Positions].[Sell]*100000)/36000,IIf([Spot Open Positions].[Buy]>0 And
[Spot Open Positions].[ITEM]='AUD/JPY' AND NOT [Spot Open
Positions].[DAY]=4,((([Buy Rate].[AUD/USD]+[Buy
Rate].[USD/JPY])/2)*[Spot Open
Positions].[Buy]*100000)/36000,IIf([Spot Open Positions].[Sell]>0 And
[Spot Open Positions].[ITEM]='AUD/JPY' AND NOT [Spot Open
Positions].[DAY]=4,((([Sell Rate].[AUD/USD]+[Sell
Rate].[USD/JPY])/2)*[Spot Open
Positions].[Sell]*100000)/36000,IIf([Spot Open Positions].[Buy]>0 And
[Spot Open Positions].[ITEM]='EUR/CHF' AND NOT [Spot Open
Positions].[DAY]=4,((([Buy Rate].[EUR/USD]+[Buy
Rate].[USD/CHF])/2)*[Spot Open
Positions].[Buy]*100000)/36000,IIf([Spot Open Positions].[Sell]>0 And
[Spot Open Positions].[ITEM]='EUR/CHF' AND NOT [Spot Open
Positions].[DAY]=4,((([Sell Rate].[EUR/USD]+[Sell
Rate].[USD/CHF])/2)*[Spot Open
Positions].[Sell]*100000)/36000,IIf([Spot Open Positions].[Buy]>0 And
[Spot Open Positions].[ITEM]='USD/CAD' AND NOT [Spot Open
Positions].[DAY]=4,([Buy Rate].[USD/CAD]*[Spot Open
Positions].[Buy]*100000)/36000,IIf([Spot Open Positions].[Sell]>0 And
[Spot Open Positions].[ITEM]='USD/CAD' AND NOT [Spot Open
Positions].[DAY]=4,([Sell Rate].[USD/CAD]*[Spot Open
Positions].[Sell]*100000)/36000)))))))))) ;

This is query3:
UPDATE [Spot Open Positions], [Sell Rate], [Buy Rate] SET [Spot Open
Positions].INTEREST = IIf([Spot Open Positions].[Buy]>0 And [Spot Open
Positions].[ITEM]='EUR/GBP' AND NOT [Spot Open
Positions].[DAY]=4,((([Buy Rate].[EUR/USD]+[Buy
Rate].[GBP/USD])/2)*[Spot Open
Positions].[Buy]*100000)/36000,IIf([Spot Open Positions].[Sell]>0 And
[Spot Open Positions].[ITEM]='EUR/GBP' AND NOT [Spot Open
Positions].[DAY]=4,((([Sell Rate].[EUR/USD]+[Sell
Rate].[GBP/USD])/2)*[Spot Open Positions].[Sell]*100000)/36000,
IIf([Spot Open Positions].[Buy]>0 And [Spot Open
Positions].[ITEM]='EUR/AUD' AND NOT [Spot Open
Positions].[DAY]=4,((([Buy Rate].[EUR/USD]+[Buy
Rate].[AUD/USD])/2)*[Spot Open
Positions].[Buy]*100000)/36000,IIf([Spot Open Positions].[Sell]>0 And
[Spot Open Positions].[ITEM]='EUR/AUD' AND NOT [Spot Open
Positions].[DAY]=4,((([Sell Rate].[EUR/USD]+[Sell
Rate].[AUD/USD])/2)*[Spot Open
Positions].[Sell]*100000)/36000,IIf([Spot Open Positions].[Buy]>0 And
[Spot Open Positions].[ITEM]='NZD/USD' AND NOT [Spot Open
Positions].[DAY]=4,([Buy Rate].[NZD/USD]*[Spot Open
Positions].[Buy]*100000)/36000,IIf([Spot Open Positions].[Sell]>0 And
[Spot Open Positions].[ITEM]='NZD/USD' AND NOT [Spot Open
Positions].[DAY]=4,([Sell Rate].[NZD/USD]*[Spot Open
Positions].[Sell]*100000)/36000,IIf([Spot Open Positions].[Buy]>0 And
[Spot Open Positions].[ITEM]='GBP/CHF' AND NOT [Spot Open
Positions].[DAY]=4,((([Buy Rate].[GBP/USD]+[Buy
Rate].[USD/CHF])/2)*[Spot Open
Positions].[Buy]*100000)/36000,IIf([Spot Open Positions].[Sell]>0 And
[Spot Open Positions].[ITEM]='GBP/CHF' AND NOT [Spot Open
Positions].[DAY]=4,((([Sell Rate].[GBP/USD]+[Sell
Rate].[USD/CHF])/2)*[Spot Open
Positions].[Sell]*100000)/36000,IIf([Spot Open Positions].[Buy]>0 And
[Spot Open Positions].[ITEM]='CHF/JPY' AND NOT [Spot Open
Positions].[DAY]=4,((([Buy Rate].[USD/CHF]+[Buy
Rate].[USD/JPY])/2)*[Spot Open
Positions].[Buy]*100000)/36000,IIf([Spot Open Positions].[Sell]>0 And
[Spot Open Positions].[ITEM]='CHF/JPY' AND NOT [Spot Open
Positions].[DAY]=4,((([Sell Rate].[USD/CHF]+[Sell
Rate].[USD/JPY])/2)*[Spot Open
Positions].[Sell]*100000)/36000)))))))))) ;

Under the conditions column I inserted the the following statements to
open the following queries:
Query1
("[ITEM]","Spot Open Positions")='EU R/USD' Or 'USD/JPY' Or 'GBP/USD'
Or 'USD/CHF' Or 'AUD/USD'
Query2
("[ITEM]","Spot Open Positions")='EU R/JPY' Or 'GBP/JPY' Or 'AUD/JPY'
Or 'EUR/CHF' Or 'USD/CAD'
Query3
("[ITEM]","Spot Open Positions")='EU R/GBP' Or 'EUR/AUD' Or 'NZD/USD'
Or 'GBP/CHF' Or 'CHF/JPY'

Please tell me if just changing the conditions statements would help
or would I have to combine the sql statements using vba. Please tell
me how because I keep getting the query to complex when tryin to
combine them.

Thank You Very Much,
Ravi
Nov 12 '05 #1
1 3199
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You might simplify it by using the Switch() function instead of the
IIf() function. E.g. (extended for clarity):

UPDATE [Spot Open Positions], [Sell Rate]
SET [Spot Open Positions].[INTEREST WED] =
((100000*3)/36000) *
Switch(
[Spot Open Positions].[ITEM]='USD/CHF', [Sell Rate].[USD/CHF],
[Spot Open Positions].[ITEM]='EUR/USD', [Sell Rate].[EUR/USD],
[Spot Open Positions].[ITEM]='USD/JPY', [Sell Rate].[USD/JPY],

<... other currencies ... >

)
WHERE [Spot Open Positions].[DAY]=4

Do the Sell Rates and Buy Rates in 2 different queries.

See the Access Help article on the Switch() function (in VBA help -
Access 2K & greater).

==

All this would not be necessary if your db design were better. You
might want to redesign some of your tables like this:

[Spot Open Positions] should have the [ITEM] (aka CurrencyType) as an
integer (Long in JET), instead of a string expression, that would
reference a table designed like the following. This assumes that the
[ITEM] column always contains a currency type. The design is correct
in any event - it would need minor modifications for other ITEM types.

CREATE TABLE CurrencyTypes (
CurrencyType Counter NOT NULL , -- AutoNumber
TypeDesc VARCHAR(25) PRIMARY KEY -- "USD" "JPY" "GBP", "USD/JPY",
etc.
)

Create a unique index on the CurrencyType column for linking/relating
purposes. The Primary Key on TypeDesc is to prevent duplicate entries
of currency types descriptions, e.g., there can only be one entry for
"USD/JPY."

Then change the Sell Rate table to something like this - to take
advantage of the data integrity capability of the CurrencyTypes table:

CREATE TABLE [Sell Rate] (
CurrencyType Long NOT NULL,
Rate CURRENCY NOT NULL,
CONSTRAINT PK_SellRate PRIMARY KEY (CurrencyType, Rate),
CONSTRAINT FK_CType FOREIGN KEY (CurrencyType)
REFERENCES CurrencyTypes (CurrencyType)
)

The Primary Key constraint prevents more than one Rate per
CurrencyType. The Foreign Key constraint looks in the table
CurrencyTypes to verify the various Currency Types.
This design would make the control of currencies much easier (you
could add new ones without having to add a new column to the Sell Rate
table). It would also make the design of queries much easier. Your
UPDATE query would be like this (for ALL currency types):

UPDATE [Spot Open Positions] AS SOP INNER JOIN [Sell Rate] AS SR
ON SOP.CurrencyTyp e = SR.CurrencyType
SET SOP.[INTEREST WED] = SR.Rate * ((100000*3)/36000)
WHERE SOP.[DAY]=4

HTH,

MGFoster:::mgf
Oakland, CA (USA)
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP7n1uIechKq OuFEgEQKJzACgqm c7KD5Zf+fe/26S4Mjc+ks/yk0AoMrc
u2FyiIlNylQJ01x 2l+4JMO2j
=cDze
-----END PGP SIGNATURE-----
ravi wrote:
I have created the following interest to calculate the interest for
the following currency pairs. I have tried to combine them in macros
using conditions but the next query that is run in the macro ends up
deleting the previous interest value that has been generated by the
query. For example if query 1 is run on the table with currency pair
USD/CHF then the interest will be updated without any problem but if
there is another entry in the table with another currency pair for
example EUR/JPY which is calculated say in query two then the interest
of USD/CHF which has been calculated previously will be deleted. I
think the only way to solve this would be to combine the queries
instead of seperating them using macro conditions. Please tell me how
I would appreciate it alot.

This is query1:
UPDATE [Spot Open Positions], [Sell Rate], [Buy Rate] SET [Spot Open
Positions].[INTEREST WED] = IIf([Spot Open Positions].[Sell]>0 And
[Spot Open Positions].[ITEM]='USD/CHF' AND [Spot Open
Positions].[DAY]=4,([Sell Rate].[USD/CHF]*[Spot Open
Positions].[Sell]*100000*3)/36000,IIf([Spot Open Positions].[Sell]>0
And [Spot Open Positions].[ITEM]='EUR/USD' AND [Spot Open
Positions].[DAY]=4,([Sell Rate].[EUR/USD]*[Spot Open
Positions].[Sell]*100000*3)/36000,IIf([Spot Open Positions].[Sell]>0
And [Spot Open Positions].[ITEM]='USD/JPY'AND [Spot Open
Positions].[DAY]=4,([Sell Rate].[USD/JPY]*[Spot Open
Positions].[Sell]*100000*3)/36000,IIf([Spot Open Positions].[Sell]>0
And [Spot Open Positions].[ITEM]='GBP/USD' AND [Spot Open
Positions].[DAY]=4,([Sell Rate].[GBP/USD]*[Spot Open
Positions].[Sell]*100000*3)/36000,IIf([Spot Open Positions].[Sell]>0
And [Spot Open Positions].[ITEM]='AUD/USD' AND [Spot Open
Positions].[DAY]=4,([Sell Rate].[AUD/USD]*[Spot Open
Positions].[Sell]*100000*3)/36000,IIf([Spot Open Positions].[Sell]>0
And [Spot Open Positions].[ITEM]='XAU/USD' AND [Spot Open


< SNIP >

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2789
by: frizzle | last post by:
Hi, I know this might sound strange but i think(/hope) it's quite simple: I'm running 2 queries in a mysql DB, first one returns 20 results. Now how can i echo results from the second query in the 1st query's result, like:
8
15228
by: Mike N. | last post by:
Hello: I am new to T-SQL programing, and relativly new to SQL statements in general, although I have a good understanding of database theory. I'm a little confused as to the fundamental differences between a view and a query, or rather, when it is more appropriate to use one vs. the other. It seems to me that most select queries can be implemented as views, and I can't see the downside to doing so.
1
6002
by: Bruce MacDonald | last post by:
I've got a question/request for the SQL gurus. I'm building a model of bandwidth demand in MS Access and want to get aggregated results for demand at each PCP in each time period. The two queries below are used to count the number of households of each Socio-Economic Type (each postcode has been allocated an SE-Type), and use that to count the number of connections requiring a bandwidth less than 512 that will be required at the PCP in...
4
1571
by: badbetty | last post by:
MS Access 97 query: Given 2 simple tables Person PersonRef (text) (primary key) Surname (text) e.g PersonRef Surname
7
21612
by: Zlatko Matiæ | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the server ? Is it possible to use parameters in pass-through queries ? An additional question: Is it possible to connect to a database on MySQL or PostgreSQL using ADO ? Is it possible to execute pass-through queries with parameters, using ADO...
13
5018
by: JayCallas | last post by:
I know this question has been asked. And the usual answer is don't use cursors or any other looping method. Instead, try to find a solution that uses set-based queries. But this brings up several questions / senarios: * I created several stored procedures that take parameters and inserts the data into the appropriate tables. This was done for easy access/use from client side apps (i.e. web-based).
1
2062
by: ferraro.joseph | last post by:
Hi, I'm querying Salesforce.com via their AJAX toolkit and outputting query results into a table. Currently, their toolkit does not possess the ability to do table joins via their structured query language, which forces me to do the join manually via arrays. Right now, I'm having trouble getting these query results (which are in
1
1203
by: jonosborne | last post by:
Hi, i hope someone can help me with this problem, i have been racking my brain for quite a while. I have two queries, both of which produce a four column table. Query A : site, dept, team, error a Query B : site, dept, team, error b I need to write a query which has the end result: Query C : site, dept, team, error a, error b However i cannot take the 'site,dept,team' information from just one table as there is info in one...
3
1543
by: billelev | last post by:
I am trying to combine two queries into one UNION query. The first sub-query works, but the second creates the following error at the end of the first iif statement: "Syntax error in union query" Does anybody know why? Select Symbol, MarketValue AS , Type, RiskType FROM . AS tmpVarPositions UNION SELECT Symbol, Sum(MarketValue), AlteredType as Type, RiskType
0
8372
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8814
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8706
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8591
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7304
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.