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

Help with joining records

Table A Table B

BOL# B_BOL#

Chargeback#
Hi All,
I have been struggling with this for the past few months. I have two
tables that I'm inner joining on BOL#=B_BOL#. This works fine. Now for
the problem....When there are chargeback# fields associated with B_BOL#
they aren't being captured as additional records. None of my tables
have primary keys because at any given time any field can contain a
"null" value, so I am unable to assign a foreign key, I think. How can
I attach the subsequent records to the main record to bring back the
additonal data? Please help!!!

Dec 14 '06 #1
4 1524
Not sure this will help, because I'm not sure, did I fully understood
your problem.
If what you mean is like fallow:

B_BOL# from Table B can be a key either with BOL# or/and Chargeback#,
then I will try as fallow:

select * from TableB B
left join TableA A1
on B.B_BOL# = A1.BOL#
left join TableA A2
on B.B_BOL# = A2.Chargeback#

If you do not want to have doble records, you can ommite it with using
is not null (if it is always like this, that the BOL# is null when
chargeback# isn't null ... and opposite).

Or You can use case statement, by removing null records.

In the future, will be better, if you put the script, or some example
data, if the script will be to complicated.

Best regards

Matik

Rnt6872 napisal(a):
Table A Table B

BOL# B_BOL#

Chargeback#
Hi All,
I have been struggling with this for the past few months. I have two
tables that I'm inner joining on BOL#=B_BOL#. This works fine. Now for
the problem....When there are chargeback# fields associated with B_BOL#
they aren't being captured as additional records. None of my tables
have primary keys because at any given time any field can contain a
"null" value, so I am unable to assign a foreign key, I think. How can
I attach the subsequent records to the main record to bring back the
additonal data? Please help!!!
Dec 14 '06 #2
Rnt6872 (r_******@msn.com) writes:
Table A Table B

BOL# B_BOL#

Chargeback#
Hi All,
I have been struggling with this for the past few months. I have two
tables that I'm inner joining on BOL#=B_BOL#. This works fine. Now for
the problem....When there are chargeback# fields associated with B_BOL#
they aren't being captured as additional records. None of my tables
have primary keys because at any given time any field can contain a
"null" value, so I am unable to assign a foreign key, I think. How can
I attach the subsequent records to the main record to bring back the
additonal data? Please help!!!
1) The standard recommendations for this type of questions, is that
you post a) CREATE TABLE statements for the tables involed. b) INSERT
statements with sample data. c) the desired result given the sample.
This sort of information helps tremendously to understand what you
want to achieve. Also it makes it very easy to develop a tested
solution.

2) If all your columns can be nullable at any time, you have a very
difficult data model to work with. Most people would probably say
that your data model is flat wrong. Maybe there is a good reason
to have all columns nullable, but it sounds very suspicious.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Dec 14 '06 #3
Erland Sommarskog wrote:
Rnt6872 (r_******@msn.com) writes:
>Table A Table B

BOL# B_BOL#

Chargeback#
Hi All,
I have been struggling with this for the past few months. I have two
tables that I'm inner joining on BOL#=B_BOL#. This works fine. Now for
the problem....When there are chargeback# fields associated with B_BOL#
they aren't being captured as additional records. None of my tables
have primary keys because at any given time any field can contain a
"null" value, so I am unable to assign a foreign key, I think. How can
I attach the subsequent records to the main record to bring back the
additonal data? Please help!!!


1) The standard recommendations for this type of questions, is that
you post a) CREATE TABLE statements for the tables involed. b) INSERT
statements with sample data. c) the desired result given the sample.
This sort of information helps tremendously to understand what you
want to achieve. Also it makes it very easy to develop a tested
solution.

2) If all your columns can be nullable at any time, you have a very
difficult data model to work with. Most people would probably say
that your data model is flat wrong. Maybe there is a good reason
to have all columns nullable, but it sounds very suspicious.
that was so diplomatic...

Given:
"None of my tables have primary keys because at any given time any field can
contain a null"

Then I would say that whoever designed this needed to pass a few more classes in
database design. Your data model needs professional help. Period.

--
Michael Austin.
Database Consultant
Dec 15 '06 #4
I think you should provide some real examples from your data also, what
you are trying to accomplish by 'bring back additional data'.

Rnt6872 wrote:
Table A Table B

BOL# B_BOL#

Chargeback#
Hi All,
I have been struggling with this for the past few months. I have two
tables that I'm inner joining on BOL#=B_BOL#. This works fine. Now for
the problem....When there are chargeback# fields associated with B_BOL#
they aren't being captured as additional records. None of my tables
have primary keys because at any given time any field can contain a
"null" value, so I am unable to assign a foreign key, I think. How can
I attach the subsequent records to the main record to bring back the
additonal data? Please help!!!
Dec 15 '06 #5

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

Similar topics

0
by: Mark | last post by:
Hi all, I have 2 files containing Id numbers and surnames (these files essentially contain the same data) I want to select distinct() and join on id number to return a recordset containing every...
7
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins"...
2
by: James | last post by:
Can anyone please shed some light on the following... I have a framework that uses dynamically created tables, named using an incremental "attribute set ID", as follows: attrdata_1 attrdata_2...
2
by: Andrew Ayers | last post by:
All, I am having a problem with an INSERT onto a table I have created. First off, here is the table: --- CREATE TABLE reg ("customer number" SERIAL PRIMARY KEY, "company name" ...
3
by: Randy Harris | last post by:
I've been trying to construct a Crosstab query (mess pasted below) that would output all rows, even if the Value (a count) is 0. No matter what I do, it only returns rows that have matching...
8
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
3
by: isaac2004 | last post by:
hello i am making a spoof online book store site for a class and I was wondering how i could fix a problem i am having. I have two tables, one the cart and the other a table with book descriptions....
4
by: bubbles | last post by:
Hi Guys n Gals, I am going to migrate an Access VBA application to SQL Server 2005. Essentially, what I need to do is to: * open a recordset * grab the ModelID and Age into variables * and...
8
by: Michael786 | last post by:
I have two tables. 1 table called T_AddressHistory (Historic Data) and the other called T_Customers (Live Editable Table) I want to append the new changes made to a the T_customers table into the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.