Click here to Skip to main content
15,916,379 members
Home / Discussions / Database
   

Database

 
AnswerRe: restore data Pin
Andy_L_J24-Dec-09 9:59
Andy_L_J24-Dec-09 9:59 
QuestionProblem in SQL server2005 Search.. Pin
hvgyufg28fh38tyr78hf23-Dec-09 17:38
hvgyufg28fh38tyr78hf23-Dec-09 17:38 
AnswerRe: Problem in SQL server2005 Search.. Pin
Blue_Boy23-Dec-09 22:35
Blue_Boy23-Dec-09 22:35 
AnswerRe: Problem in SQL server2005 Search.. Pin
Eddy Vluggen24-Dec-09 7:11
professionalEddy Vluggen24-Dec-09 7:11 
QuestionSQL 2005 Express - Complex Query Help - Date Range Pin
Jordon4Kraftd23-Dec-09 8:32
Jordon4Kraftd23-Dec-09 8:32 
AnswerRe: SQL 2005 Express - Complex Query Help - Date Range Pin
keyur satyadev24-Dec-09 20:29
keyur satyadev24-Dec-09 20:29 
GeneralRe: SQL 2005 Express - Complex Query Help - Date Range Pin
Jordon4Kraftd5-Jan-10 12:55
Jordon4Kraftd5-Jan-10 12:55 
GeneralRe: SQL 2005 Express - Complex Query Help - Date Range Pin
Jordon4Kraftd14-Jan-10 6:33
Jordon4Kraftd14-Jan-10 6:33 
I thought i had it now i know i don't.

What i need to do is get all outstanding invoice payments and thier amounts owing for a end date. So I want to know the status of the account for October 31, 2009.

Here is how i am able to get it for what ever is in the database, now i just need to edit it for an end date.

SELECT        InvoicePayment.DateCreated AS InvoicePaymentDate,
 InvoicePayment.InvoiceID,
 InvoicePayment.Amount,
 Customer.Name, 
 Invoice.CustomerID,
 Invoice.InvoiceNumber
FROM InvoicePayment INNER JOIN
	Invoice ON InvoicePayment.InvoiceID = Invoice.ID INNER JOIN
	Customer ON Invoice.CustomerID = Customer.ID INNER JOIN
	PaymentMethod ON InvoicePayment.PaymentMethodID = PaymentMethod.ID LEFT OUTER JOIN
	CustomerAccountPaymentDetail ON InvoicePayment.ID = CustomerAccountPaymentDetail.InvoicePaymentID
WHERE  Customer.ID = @CustomerID
	and (CustomerAccountPaymentDetail.ID IS NULL) 
	AND (Invoice.Void = 'False') 
	AND (PaymentMethod.IsCredit = 'True')
union
SELECT	InvoicePayment.DateCreated AS InvoicePaymentDate, 
	InvoicePayment.InvoiceID, 
	InvoicePayment.Amount - SUM(case CustomerAccountPayment.Void 
		when 'True' then 0 
		when 'False' then ROUND(CustomerAccountPaymentDetail.Amount, 2)
	end) AS Amount, 
	Customer.Name, 
	Invoice.CustomerID, 
	Invoice.InvoiceNumber
FROM InvoicePayment INNER JOIN
                      Invoice ON InvoicePayment.InvoiceID = Invoice.ID INNER JOIN
                      Customer ON Invoice.CustomerID = Customer.ID INNER JOIN
                      CustomerAccountPaymentDetail ON InvoicePayment.ID = CustomerAccountPaymentDetail.InvoicePaymentID INNER JOIN
                      PaymentMethod ON InvoicePayment.PaymentMethodID = PaymentMethod.ID INNER JOIN
                      CustomerAccountPayment ON CustomerAccountPaymentDetail.CustomerAccountPaymentID = CustomerAccountPayment.ID
WHERE (Invoice.Void = 'False') 
	AND (PaymentMethod.IsCredit = 'True') 
	and Invoice.CustomerID = @CustomerID
GROUP BY InvoicePayment.DateCreated, InvoicePayment.InvoiceID, Invoice.InvoiceNumber, InvoicePayment.Amount, InvoicePayment.DateCreated, Customer.Name, 
                      Invoice.CustomerID
HAVING      (SUM(case CustomerAccountPayment.Void 
		when 'True' then 0 
		when 'False' then ROUND(CustomerAccountPaymentDetail.Amount, 2)
	end)  <> InvoicePayment.Amount)
ORDER BY Customer.Name


This returns a list of all invoice payments that have amounts due and thier amount that is due.

The first query gets all invoice charges that don't have a customer payment for the invoice charge, that is the easy one.
The second query gets all the invoices that have a partial payment or an overpayment (could happen with old system, not with mine...but yeah they exist).

My head hurts I don't know how to filter this beast for an end date. I guess i need to run the query on customer payment/customerpaymentdetails that are already filtered by the end date. And then run this query against that, accept i don't know how, i think that is the issue, my lack of sql experience.

Jordon.
GeneralRe: SQL 2005 Express - Complex Query Help - Date Range Pin
Jordon4Kraftd14-Jan-10 7:11
Jordon4Kraftd14-Jan-10 7:11 
QuestionWhat database to choose Pin
cdpace23-Dec-09 5:07
cdpace23-Dec-09 5:07 
AnswerRe: What database to choose Pin
loyal ginger23-Dec-09 5:46
loyal ginger23-Dec-09 5:46 
GeneralRe: What database to choose Pin
Corporal Agarn23-Dec-09 5:57
professionalCorporal Agarn23-Dec-09 5:57 
GeneralRe: What database to choose Pin
cdpace23-Dec-09 10:55
cdpace23-Dec-09 10:55 
AnswerSupport Multiple Databases Pin
David Mujica23-Dec-09 5:58
David Mujica23-Dec-09 5:58 
GeneralRe: Support Multiple Databases Pin
cdpace23-Dec-09 10:54
cdpace23-Dec-09 10:54 
Questionsqlite Pin
jashimu23-Dec-09 3:34
jashimu23-Dec-09 3:34 
AnswerRe: sqlite Pin
dxlee23-Dec-09 4:17
dxlee23-Dec-09 4:17 
GeneralRe: sqlite Pin
jashimu23-Dec-09 4:34
jashimu23-Dec-09 4:34 
GeneralRe: sqlite Pin
dxlee23-Dec-09 5:38
dxlee23-Dec-09 5:38 
Question2 SQL quesions: address book Pin
Dmitry Khudorozhkov22-Dec-09 10:27
Dmitry Khudorozhkov22-Dec-09 10:27 
AnswerRe: 2 SQL quesions: address book Pin
Mycroft Holmes22-Dec-09 12:10
professionalMycroft Holmes22-Dec-09 12:10 
GeneralRe: 2 SQL quesions: address book Pin
Dmitry Khudorozhkov22-Dec-09 13:17
Dmitry Khudorozhkov22-Dec-09 13:17 
QuestionQuery to Test for SA [modified] Pin
mobius11100122-Dec-09 7:30
mobius11100122-Dec-09 7:30 
AnswerRe: Query to Test for SA Pin
Dr.Walt Fair, PE22-Dec-09 7:47
professionalDr.Walt Fair, PE22-Dec-09 7:47 
GeneralRe: Query to Test for SA Pin
mobius11100122-Dec-09 7:52
mobius11100122-Dec-09 7:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.