473,387 Members | 1,899 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,387 software developers and data experts.

A query problem

Hi All,
I have one table with two tables linked to two index fields,

tblMain, MainId, CashId, CreditId
tblCash Cashid, CashValue
tblCredit, CreditId, CreditValue

Each record is either a credit or a cash record, and so either the CashId or
the CreditId will be completed. Is there a way I can query this info
(without changing the underlying data) to give me a table containing two
fields, the MainId and a Value field, containing the the cash value for
cash records, and credit value for credit records. ?
As usual any advice welcome.

Gerry Abbott


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.518 / Virus Database: 316 - Release Date: 11/09/03
Nov 12 '05 #1
2 1431
Apologies for the added virus message with the original post , I have
removed it.
I have also found a solution.
If anyone has a better one please post.

SELECT tblMain.Id, tblCash.CashValue,
tblCredit.CreditValue,
IIf([cashValue] Is Null,[creditValue],[cashvalue]) AS [Value]
FROM tblCash RIGHT JOIN
(tblCredit RIGHT JOIN tblMain ON tblCredit.CreditId = tblMain.CreditId)
ON tblCash.CashId = tblMain.CashId;
Gerry Abbott
"Gerry Abbott" <pl****@ask.ie> wrote in message
news:z4*****************@news.indigo.ie...
Hi All,
I have one table with two tables linked to two index fields,

tblMain, MainId, CashId, CreditId
tblCash Cashid, CashValue
tblCredit, CreditId, CreditValue

Each record is either a credit or a cash record, and so either the CashId or the CreditId will be completed. Is there a way I can query this info
(without changing the underlying data) to give me a table containing two
fields, the MainId and a Value field, containing the the cash value for
cash records, and credit value for credit records. ?
As usual any advice welcome.

Gerry Abbott


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.518 / Virus Database: 316 - Release Date: 11/09/03

Nov 12 '05 #2
Hello,

You should try using a UNION query, a union query isn't supported by the
query builder so you'll have to write in sql. Below your text you can find a
example that should work on the database discribed by you in your message.
I have one table with two tables linked to two index fields,

tblMain, MainId, CashId, CreditId
tblCash Cashid, CashValue
tblCredit, CreditId, CreditValue

Each record is either a credit or a cash record, and so either the CashId or the CreditId will be completed. Is there a way I can query this info
(without changing the underlying data) to give me a table containing two
fields, the MainId and a Value field, containing the the cash value for
cash records, and credit value for credit records. ?


Try using this union query:

SELECT tblmain.MainId, tblCash.CashValue
FROM tblCash INNER JOIN tblmain ON tblCash.Cashid = tblmain.Cashid
WHERE (((tblmain.CreditId) Is Null))
UNION SELECt tblmain.MainId,tblCredit.CreditValue
FROM tblCredit INNER JOIN tblmain ON tblCredit.CreditId =
tblmain.CreditId
WHERE (((tblmain.Cashid) Is Null));

NP! Fons
Nov 12 '05 #3

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

Similar topics

13
by: Wescotte | last post by:
Here is a small sample program I wrote in PHP (running off Apache 1.3.31 w/ PHP 5.0.1) to help illustrates problem I'm having. The data base is using DB2 V5R3M0. The client is WinXP machine using...
3
by: Brian Oster | last post by:
After applying security patch MS03-031 (Sql server ver 8.00.818) a query that used to execute in under 2 seconds, now takes over 8 Minutes to complete. Any ideas on what the heck might be going...
1
by: Jeff Blee | last post by:
I hope someone can help me get this graph outputing in proper order. After help from Tom, I got a graph to display output from the previous 12 months and include the average of that output all in...
8
by: Adam Louis | last post by:
I would like help resolving this problem. I'm a novice who's been hired to query a hospital database and extract useful information, available to me only in a dynamically generated, downloadable...
6
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access...
4
by: Apple | last post by:
1. I want to create an autonumber, my requirement is : 2005/0001 (Year/autonumber), which year & autonumber no. both can auto run. 2. I had create a query by making relation to a table & query,...
11
by: Andy_Khosravi | last post by:
My problem: I'm having trouble with a query taking much too long to run; a query without any criteria evaluating only 650 records takes over 300 seconds to run (over the network. On local drive...
4
by: Konrad Hammerer | last post by:
Hi! I have the following problem: I have a query (a) using another query (b) to get the amount of records of this other query (b), means: select count(MNR) as Number from...
4
by: Stan | last post by:
I am using MS Office Access 2003 (11.5614). My basic question is can I run a query of a query datasheet. I want to use more that one criteria and can not get that query to work. I thought I...
2
by: existential.philosophy | last post by:
This is a new problem for me: I have some queries that open very slowly in design view. My benchmark query takes about 20 minutes to open in design view. That same query takes about 20 minutes...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
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...

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.