Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MSSQL query dilema

Posted on 2011-03-16
8
Medium Priority
?
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

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

Assisted Solution

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

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

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.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

660 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