Solved

Need help with a "Join" script

Posted on 2008-06-25
8
208 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

920 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

14 Experts available now in Live!

Get 1:1 Help Now