Solved

MSSQL query dilema

Posted on 2011-03-16
8
236 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 19

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 19

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
 

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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 19

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 250 total points
ID: 35153863
0
 
LVL 19

Assisted Solution

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

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

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

12 Experts available now in Live!

Get 1:1 Help Now