473,395 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to build this field expression

I've 2 tables as below (1 to 1 relationship between ID's)

tableGames
ID | Home | Away | Result|
1 | team_A | team_B | H |
2 | team_C | team_D | D |
3 | team_E | team_F | A |
4 | team_G | team_H | H |
....
(H=home team win, D=Draw, A=Away team win)

tableOdds
ID| Home | Draw | Away |
1 | 1,40 | 3,30 | 6,00 |
2 | 1,15 | 2,40 | 9,00 |
3 | 2,60 | 3,00 | 3,20 |
4 | 1,90 | 3,10 | 2,50 |
....

I want to build an expression to achieve a result table like below;
tableOddResults
ID | Home | Away | Odd |
1 | team_A | team_B | 1,40 |
2 | team_C | team_D | 2,40 |
3 | team_E | team_F | 3,20 |
4 | team_G | team_H | 1,90 |

In other words I want to get the odd value from tableOdds corresponding to
the game result.
Nov 12 '05 #1
3 2713
Your problem here stems from the fact that your TableOdds table is not
normalised. If you had:

ID | Type | Val |
1 | H | 1,40 |
etc.

then your query becomes trivial.

P
"King Jeremy" <vi********@hotmail.com> wrote in message
news:bn**********@list.ege.edu.tr...
I've 2 tables as below (1 to 1 relationship between ID's)

tableGames
ID | Home | Away | Result|
1 | team_A | team_B | H |
2 | team_C | team_D | D |
3 | team_E | team_F | A |
4 | team_G | team_H | H |
...
(H=home team win, D=Draw, A=Away team win)

tableOdds
ID| Home | Draw | Away |
1 | 1,40 | 3,30 | 6,00 |
2 | 1,15 | 2,40 | 9,00 |
3 | 2,60 | 3,00 | 3,20 |
4 | 1,90 | 3,10 | 2,50 |
...

I want to build an expression to achieve a result table like below;
tableOddResults
ID | Home | Away | Odd |
1 | team_A | team_B | 1,40 |
2 | team_C | team_D | 2,40 |
3 | team_E | team_F | 3,20 |
4 | team_G | team_H | 1,90 |

In other words I want to get the odd value from tableOdds corresponding to
the game result.

Nov 12 '05 #2
If your table names and the field names are exactly as you mentioned, paste
the following into a new query.

SELECT tableGames.ID, tableGames.Home, tableGames.Away, tableGames.Result,
Format(IIf([Result]="H",[tableOdds].[Home],IIf([Result]="D",
[tableOdds].[Draw],[tableOdds].[Away])),"Fixed") AS Odds
FROM tableGames INNER JOIN tableOdds ON tableGames.ID = tableOdds.ID;

If there is no value in the result field it will always pull the value from
the away odds without placing in another nexted IIf statement.

Some one else might have a better way to do this with striaght SQL without
using nexted IIf statements

Stewart
"King Jeremy" <vi********@hotmail.com> wrote in message
news:bn**********@list.ege.edu.tr...
I've 2 tables as below (1 to 1 relationship between ID's)

tableGames
ID | Home | Away | Result|
1 | team_A | team_B | H |
2 | team_C | team_D | D |
3 | team_E | team_F | A |
4 | team_G | team_H | H |
...
(H=home team win, D=Draw, A=Away team win)

tableOdds
ID| Home | Draw | Away |
1 | 1,40 | 3,30 | 6,00 |
2 | 1,15 | 2,40 | 9,00 |
3 | 2,60 | 3,00 | 3,20 |
4 | 1,90 | 3,10 | 2,50 |
...

I want to build an expression to achieve a result table like below;
tableOddResults
ID | Home | Away | Odd |
1 | team_A | team_B | 1,40 |
2 | team_C | team_D | 2,40 |
3 | team_E | team_F | 3,20 |
4 | team_G | team_H | 1,90 |

In other words I want to get the odd value from tableOdds corresponding to
the game result.



Nov 12 '05 #3
You need to do a join with an iif

Select tableGames.ID, tableGames.Home, tableGames.Away,
iif(tableGames.Result = 'H', tableOdds.Home,
iif(tableGames.Result='D',table.Odds.Draw,
iif(tableGames.Result='A', tableOdds.Away, 'Unknown'))) as Odd
From tableGames Left Join tableOdds On tableGames.ID = tableOdds.ID
"King Jeremy" <vi********@hotmail.com> wrote in message news:<bn**********@list.ege.edu.tr>...
I've 2 tables as below (1 to 1 relationship between ID's)

tableGames
ID | Home | Away | Result|
1 | team_A | team_B | H |
2 | team_C | team_D | D |
3 | team_E | team_F | A |
4 | team_G | team_H | H |
...
(H=home team win, D=Draw, A=Away team win)

tableOdds
ID| Home | Draw | Away |
1 | 1,40 | 3,30 | 6,00 |
2 | 1,15 | 2,40 | 9,00 |
3 | 2,60 | 3,00 | 3,20 |
4 | 1,90 | 3,10 | 2,50 |
...

I want to build an expression to achieve a result table like below;
tableOddResults
ID | Home | Away | Odd |
1 | team_A | team_B | 1,40 |
2 | team_C | team_D | 2,40 |
3 | team_E | team_F | 3,20 |
4 | team_G | team_H | 1,90 |

In other words I want to get the odd value from tableOdds corresponding to
the game result.

Nov 12 '05 #4

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

Similar topics

4
by: Tom Esker | last post by:
I've got Javascript in a form that adds up all of the numbers in a column of form fields and displays a total. It works great if every field has an initial value of 0, but if any of them are null,...
9
by: Harry | last post by:
Hi there, does anyone know how I can build a regular expression e.g. for the string.search() function on runtime, depending on the content of variables? Should be something like this: var...
15
by: grunar | last post by:
After some thought on what I need in a Python ORM (multiple primary keys, complex joins, case statements etc.), and after having built these libraries for other un-named languages, I decided to...
0
by: dba123 | last post by:
THERE HAS TO BE A SOLUTION FOR THIS!!!! How can I get around the limitation in SSRS 2005 of being able to SUM a Group referenced field in my FOOTER!!! It's driving me nuts My footer field's...
7
by: Tizzah | last post by:
What is wrong with that? regex = /^(http|https):\/\/+({1}+)*\.{2,5}(({1,5})?\/.*)?$/ if(field.hpage.value != regex.test(field.hpage.value)){ alert("Bad Homepage") field.hpage.focus()...
4
by: cpaul | last post by:
So in a table I have a field that I want populated with the result of an arithmatic expression. For example, one field named VALUE, populated with a form, is a variable in an expression like VALUE *...
9
by: Alan Mailer | last post by:
Ok, my Access 2002 language writing skills are VERY rusty,. I would know how to do what I need using SQL Server's "Coalesce' function, but I don't have that available to me in the Access 2002...
3
by: mnjkahn via AccessMonster.com | last post by:
I'm running Access 2003, modifying a query that has over 45 fields. When I right click on the field name in Query Design View, and then click Build, Access crashes before the Build window...
6
by: shalskedar | last post by:
In the Report 1 of the fields contain expression.When i m trying to find the grandtotal for this field it gives me error.. For ex- The field expression is Format(,"0.00") to limit the field value...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...

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.