943,791 Members | Top Members by Rank

Ad:
Apr 21st, 2009
0

Extracting data from 3 tables for a DataReport

Expand Post »
Hi,
Consider there are 3 tables as following:

Table1
=============================================================================================
| SerialNum | Date | B | C | D | Table2Number | Table2_Amount | Table3Number | Table3_Amount|
=============================================================================================
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
=============================================================================================

Table2
=============================================
| SerialNum | Date | B | C | D | E | Amount |
=============================================
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
=============================================

Table3
=============================================
| SerialNum | Date | B | C | D | E | Amount |
=============================================
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
=============================================

Primary keys for each table:
SerialNum field is primary key for the respective tables.

Foreign keys in Table1:
Table2Number :::> Taken from primary key of Table2
Table2_Amount :::> Taken from Amount field of Table2
Table3Number :::> Taken from primary key of Table3
Table3_Amount :::> Taken from Amount field of Table3

Our main area of concern is for Table1. I want to create a DataReport1 in which i will be extracting details from all the above tables based on certain conditions. The situation is that at times either (not both) of the Table2Number or Table3Number field in Table1 will have "NULL" value so, the DataReport1 that i will create must extract all the data from Table1 along with data from Table2 or Table3, whichever's foreign key values in Table1 is not "NULL" value.

NOTE:
1) The extraction is based on either Monthly basis or yearly basis. (i used, WHERE Date <= ? or >= ?)
2) Data entry for Table1 is made such a way that ONLY one of the fields that is, Table2Number or Table3Number must be "NULL".

I had tried many SQL querys to get it right but it extracts both the tables, Table2 and Table3 what ever be the value in the foreign keys Table2Number or Table3Number .

Pls help me solve this. Thank you.
Reputation Points: 26
Solved Threads: 0
Junior Poster in Training
RahulV is offline Offline
92 posts
since Jun 2007
Apr 22nd, 2009
0

Re: Extracting data from 3 tables for a DataReport

I know its a bit hard to perform
Reputation Points: 26
Solved Threads: 0
Junior Poster in Training
RahulV is offline Offline
92 posts
since Jun 2007
Apr 22nd, 2009
0

Re: Extracting data from 3 tables for a DataReport

Please post some sample data.
Say 5 records for each table.
and the desired result output.
I will try help u out with this. by the way, which db r u using? MS-Access or SQL Server or...

Regards
Shaik Akthar
Reputation Points: 26
Solved Threads: 40
Posting Whiz
aktharshaik is offline Offline
316 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: how to resize the coordinates of the picture
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: mshflexgrid





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC