Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MSSQL query dilema

Posted on 2011-03-16
8
Medium Priority
?
249 Views
Last Modified: 2012-05-11
I have two tables.

invoice & banking

Under my banking table I have check number, and under invoice table, I have the same check number.

I need it to return all my check details and include the invoice number(s) as well.

So my query returns all the checks I have written just fine, but I need it to also show me which invoice(s) I have it written for.

One check may have paid several invoices.

Thanks
0
Comment
Question by:aka_FATCAT
  • 4
  • 2
  • 2
8 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35153795
you must be geeting check information only form banking table

to get invoices get by joining to invoices table

something like this

select b.checknumber , i.invoicenumber form banking b
inner join invoices i on b.checknumber = i.checknumber
and b.acountnuber =12345

chngae the data as per your requirement

or share your query and field details
0
 
LVL 20

Expert Comment

by:Rikin Shah
ID: 35153806
SELECT CheckNumber, InvoiceDetails from InvoiceTable
INNER JOIN BankingTable ON
InvoiceTable.CheckNumber=BankingTable.CheckNumber

Open in new window

0
 
LVL 20

Expert Comment

by:Rikin Shah
ID: 35153809
Corrections...

 
SELECT CheckNumber, InvoiceDetails from InvoiceTable
INNER JOIN BankingTable ON
InvoiceTable.CheckNumber=BankingTable.CheckNumber
GROUP BY InvoiceTable.CheckNumber

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:aka_FATCAT
ID: 35153824
Its returning the data line by line.

What i want returned on the same line is,

check_number - pay_to - amount - invoice_number1, invoice_number2, invoice_number3, check_date
0
 

Author Comment

by:aka_FATCAT
ID: 35153839
Column 'Invoice.invoice_number' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.




SELECT i.Check_Number, i.Invoice_number 
from Invoice i 
LEFT OUTER JOIN Banking b ON i.Check_Number=b.Check_Number
GROUP BY i.Check_Number

Open in new window

0
 
LVL 20

Expert Comment

by:Rikin Shah
ID: 35153856
Apology... corrections...

SELECT i.Check_Number, i.Invoice_number
from Invoice i
LEFT OUTER JOIN Banking b ON i.Check_Number=b.Check_Number
ORDER BY i.Check_Number
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 1000 total points
ID: 35153863
0
 
LVL 20

Assisted Solution

by:Rikin Shah
Rikin Shah earned 1000 total points
ID: 35153870
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

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 ?
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

885 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