Click here to Skip to main content
15,902,635 members
Home / Discussions / Database
   

Database

 
QuestionRe: How to create FileName or Folder name with space ? Pin
Md. Marufuzzaman27-Dec-09 2:57
professionalMd. Marufuzzaman27-Dec-09 2:57 
AnswerRe: How to create FileName or Folder name with space ? [modified] Pin
Md. Marufuzzaman26-Dec-09 2:28
professionalMd. Marufuzzaman26-Dec-09 2:28 
Questionrestore data Pin
Akhteruzzaman24-Dec-09 2:00
Akhteruzzaman24-Dec-09 2:00 
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 
First off, I inherited this database and its database structure, Second I am mainly a C# programmer and my database query skills are lacking and could use improvement I know that. I have avoided this bugger for a too long so now I ask the community for help.

I'll break this down to 3 parts, 1: What my DB looks like (the important stuff), 2. What I want to accomplish, 3: Where I am at.

1: Tables & relations (I can supply you with a create script and sample data, only needed fields are seen)

TABLE:CustomerAccountPayment
ID, PK, int
CusotmerID, FK, int
EntryDate, DateTimeAmount, numeric(18,2)
Void, bit
FloatingAmount, numeric(18,2) (Positive Only, means they overpaid for some reason)
Amount = sum(CustomerAcountPaymentDetail.Amount)
Total = Amount + FloatingAmount

TABLE:CustomerAccountPaymentDetail
ID, PK, int
CustomerAccountPaymentID, FK, int (CusotmerAccountPayment.ID)
InvoicePaymentID, FK, int (InvoicePayment.ID)
Amount, numeric(18,2)
IsFloat, bit (Is true when the paymentdetail is covered under the customeraccountpayment.FloatingAmount)

TABLE:InvoicePayment
ID, PK, int
InvoiceID, FK, int
PaymentMethodID, FK, int (PaymentMethod.ID)
Amount, numeric(18,2)
DateCreated, datetime

TABLE: PaymentMethod
ID, PK, int
Name, nvarchar(50)
IsCredit, bit (Identifies it is a credit charge type to account when set to 'true')

2: What i need
I have been developing a report that is a Customer account balance sheet, it shows thier current customer account balance (sum(InvoicePayment.Amount) - sum(CustomerAcocuntPayment.Total) - and what they have paid (CustomerAccountPayment) for a date range, and the age of outstanding the charges (InvoicePayments).

I need to retreive thier balance before the StartDate.
I need to retreive What they have charged and paid between the start and enddate.
I need to retreive the remainder, after EndDate.

This is all for a particular customer and the PaymentMethod.IsCredit = true. That being true means it was charged to their "Account".

3:What i got.

To determine thier current balance i do these 2 queries.
TotalCharged - TotalPaid.
TotalCharged
SELECT SUM(InvoicePayment.Amount) AS TotalCharged
FROM            InvoicePayment INNER JOIN
                         PaymentMethod ON InvoicePayment.PaymentMethodID = PaymentMethod.ID INNER JOIN
                         Invoice ON InvoicePayment.InvoiceID = Invoice.ID
WHERE        (PaymentMethod.IsCredit = 1) 
AND (Invoice.Void = 0) 
AND (Invoice.CustomerID = @CustomerID)


TotalPaid
SELECT (sum(CustomerAccountPayment.Amount) + Sum(FloatingAmount)) as TotalPaid
FROM CustomerAccountPayment 
WHERE CustomerID = @CustomerID 
AND Void = 0 


Now the problem is that I need to make a customer sheet for October 2009. StartDate = 20091001, EndDate = 20091031.

How do I exclude InvoicePayments (these are really charges on invocies..bad name) that are covered under a customer payment made after October 2009 but include the invoice charges for october only? Meaning there is a relation between a invoicepayment and a customerpayment made in november (there could even be a voided one CustomerAccountPayment.Void = 'True')

How do I get the balance previous to October 2009?

I just can't seem to get the proper results with all my test queries (Which are numerous..) I am hoping to get a new start point for these queries from the community... I think i am missing a technique i am jsut not aware of.

Thanks,
Jordon.
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 
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 

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.