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

JOIN from 2 Tables and combine several records into 1 record

Thank you for your assistance. I am a novice looking to JOIN and append or combine records from 2 current Tables into 2 new Tables named below. I have been able to JOIN Tables with the script below. My problem is if I don’t use the WHERE clause in my script below, the script can query up to 3 records with the same “LoanNo” due to the fact that there can be up to 3 “TypeCodes” in each Table (Borrower, Co-Borrower 1 and Co-Borrower 2 represented by 1, 2 and 3 in the “TypeCode” columns) or up to 6 records in each Table with the same “LoanNo” with the same aforementioned “TypeCode’s” however this happens because of a different date in the DX.FundDate column. The way it is now if there are 3 borrowers per loan, there can be 2 loans a 1st Lien and a 2nd Lien and I have to combine all of these records manually in Excel.

My goal is to append or combine these records to have all 3 “TypeCode’s” on 1 record with 19 columns in a new Table as follows:

Part 1- (DX.LoanNo, DX.FundDate, BR.BorrLastName, BR.BorrFirstName, BR.BorrMiddleName, BR.BorrSSN, BR.BorrTypeCode, DX.Address, DX.LienCode) = (TypeCode 1)

Part 2 – (BR.BorrLastName, BR.BorrFirstName, BR.BorrMiddleName, BR.BorrSSN, BR.BorrTypeCode) = (TypeCode 2)

Part 3 – (BR.BorrLastName, BR.BorrFirstName, BR.BorrMiddleName, BR.BorrSSN, BR.BorrTypeCode) = (TypeCode 3)

*NOTE: There is a “LienCode” in each Table (1st lien =1 and 2nd lien = 2). I would then have 2 new Tables representing Table.Lien 1 and Table.Lien 2. I eventually want to send these new Tables into Access via Excel as to not lose any data due to the Varchar 255 format in SQL. This is the way the DB came.

Current Tables (all are Varchar 255 nulls allowed):
Table 1=DX
DX.LoanNo - (no leading zeros or alphas)
DX.FullName - (text only with commas separating last, first and middle names)
DX.SSN - (some records have dashes and some don’t)
DX.TypeCode - (single digit from 1-3)
DX.FundDate - (date)
DX.Address - (alphanumeric)
DX.LienCode - (single digit from 1-2)

Table 2=BR (all are Varchar 255 nulls allowed)
BR.BorrLoanNo - (no leading zeros or alphas)- (same info as DX.LoanNo)
BR.BorrLastName - (text)
BR.BorrFirstName - (text)
BR.BorrMiddleName - (text)
BR.BorrSSN - (same as above) – (some fields are missing data or vice-versa with DX.SSN)
BR.BorrTypeCode - (single digit from 1-3) – (Same info as DX.TypeCode)


Current Script:
Expand|Select|Wrap|Line Numbers
  1. SELECT  DX.LoanNo, DX.FundDate, BR.BorrLastName, BR.BorrFirstName,
  2. BR.BorrMiddleName, BR.BorrSSN, BR.BorrTypeCode, DX.Address, DX.LienCode
  3.  
  4. FROM         dbo.DX LEFT OUTER JOIN
  5.                       dbo.BR ON dbo.DX.LoanNo = dbo.BR.BorrLoanNo
  6.  
  7. WHERE     (dbo.BR.BorrTypeCode = '1') AND (dbo.DX.Lien = '1')
  8.  
  9. ORDER BY dbo.DX.LoanNo
I have MS SQL Server Management Studio and MS Office 2007 on Windows XP Pro. Again thank you for your help.

Blue
Mar 18 '08 #1
1 3398
ck9663
2,878 Expert 2GB
Sometimes it's easier to just post some sample data, even if those are just mock values and what you're trying to achieve. Sorry, it would be faster for me to read that way rather than goes through this. Maybe the others can help.

-- CK
Mar 19 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: jhutchings | last post by:
Hello everyone, I have a database where I collect shipment data from various tables. However, I have a problem. Whenever I want to see shipping data for orders that were set to ship on or before...
4
by: musicloverlch | last post by:
I have a table with multiple records in it. I am being forced to combine multiple records into one record in order to be uploaded to a website, and I only get one record per client. How can I...
6
by: tromped | last post by:
I need to know urgently how to combine 2 records in 1.
2
by: zwasdl | last post by:
I'm using access to connect to Oracle via ODBC. I can also connect to Oracle via sql*plus. Can I write a query to join tables from different schema? If so, how? Thanks a million! Wei
4
by: ske | last post by:
Hi I've inherited an Access database where there is a form setup which prints out a Job Sheet. This works fine with one record. However I need to set it to loop through several records and print...
7
by: RobertJohn | last post by:
I am using Access 2007, and I have a database in which one field is likely to have the same value for several records (eg the Age field in a table of students). How can I set this field on a form so...
21
patjones
by: patjones | last post by:
Hi all: My newest project involves creating a small help desk database for our customer service division to use. What will happen is that an employee will call up, explain his/her issue, and...
4
werks
by: werks | last post by:
Hello experts could someone tell me how can i combine multiple records into one value. Sample in MS Access: (Lastname & "" & "," & " " & Firstname) AS Name How can i do this in MySQL?..tnx in...
1
by: liveevil | last post by:
Hi all, I'm trying to join 2 tables as follow Table 1: userId Name 1 Tom 2 John Table 2:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.