Solved

Need help with a "Join" script

Posted on 2008-06-25
8
207 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
The viewer will learn how to dynamically set the form action using jQuery.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now