Solved

Need help with a "Join" script

Posted on 2008-06-25
8
212 Views
Last Modified: 2012-05-05
Trying to get info from from two tables using a join. Tables are Billing Header and Billing Detail. From billing header I want "billing" and "primary code" from Billing Detail I want "Service Date 1". Problem is.. in Billing Header there is one record per bill, in Billing Detail there can me multiple records per bill depending on how many line items were on the bill but the service date is the same for the entire bill. How do I script the query? There are two common colunms in each table, Chart and Billing.
0
Comment
Question by:wdabbs
  • 4
  • 4
8 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 21868043
try this:

select b.billing, b.primarycode, bh.servicedate1 from billingheader b
join billingdetail bh on b.chart = bh.chart and b.billing = bh.billing
0
 

Author Comment

by:wdabbs
ID: 21868275
select Billing Header.Billing, Billing Header.Primary Code, Billing Detail.Service Date 1 from b
join Billing Detail bh on b.chart = bh.chart and Billing Detail.billing = Billing Header.billing   <- is this how it should look?
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 21868301
no quite.  you'll need brackets around the table names if they are two separate words:

select b.Billing, b.Primary Code, bhService Date 1
from [Billing Header] b
join [Billing Detail] bh on b.chart = bh.chart and bh.billing = b.billing  
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:wdabbs
ID: 21868408
Getting select b.Billing, b.Primary Code, bhService Date 1
from [Billing Header] b
join [Billing Detail] bh on b.chart = bh.chart and bh.billing = b.billing
*** ERROR: Incorrect syntax near the keyword 'Primary'. ***

0
 
LVL 60

Expert Comment

by:chapmandew
ID: 21868418
whoops...missed that one

select b.Billing, b.[Primary Code], bh.[Service Date 1]
from [Billing Header] b
join [Billing Detail] bh on b.chart = bh.chart and bh.billing = b.billing  
0
 

Author Comment

by:wdabbs
ID: 21868593
Thank you sir! You are most kind and generous with your knowledge :) So the need to "Billing Header" b and "Billing Detail" bh? is that just to adreviate?? and what is operator "on", what's is saying??
0
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 21868621
On is part of the ANSI join statement I used in the query.  As for b and bh, I used them as table aliases.
0
 

Author Closing Comment

by:wdabbs
ID: 31470675
Thanks!
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question