473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Find first payment

I have a payment journal table that is similar to the following:

ClientID Date Amount Category
123 1/2/01 -100 PMT
123 1/5/01 100 NSF
123 1/20/01 -35 PMT


I need to be able to find the first payment from each clientid that does NOT have a corresponding NSF (which will always be Amount *-1). I've tried to do this with a JOIN but I'm not having any luck.
Sep 6 '07 #1
10 1487
mwasif
802 Expert 512MB
Post the query you have made so far. What is the data type of Date column?
Sep 6 '07 #2
Post the query you have made so far. What is the data type of Date column?
The Date is a date type field. The query I have so far looks like:

Expand|Select|Wrap|Line Numbers
  1. SELECT a.clientid a.effdt, a.amount, a.category
  2. FROM journal a, journal b
  3. WHERE a.amount <> (b.amount)*-1
  4. SORT BY effdt
Sep 6 '07 #3
Still looking for an answer to this....anyone?
Sep 13 '07 #4
amitpatel66
2,367 Expert 2GB
Still looking for an answer to this....anyone?
Try below query:

Expand|Select|Wrap|Line Numbers
  1. SELECT j.* from jnl j where j.caty = 'PMT' AND abs(j.amt) NOT IN (SELECT amt from jnl where caty = 'NSF' and cid = j.cid)
  2.  
Sep 13 '07 #5
This is close to what I need. Here is the issue, if there is one NSF for $160 and then 3 payments for $160, the one NSF will cancel out all three payments.

Is there any easy way to compare them ledger style (compare 1st payment to 1st NSF, if they are the same ignore) and loop until it finds the 1st time when they do not match up.

Is there an easier way to do this? Should I be using some PHP with a more basic query?
Sep 19 '07 #6
amitpatel66
2,367 Expert 2GB
This is close to what I need. Here is the issue, if there is one NSF for $160 and then 3 payments for $160, the one NSF will cancel out all three payments.

Is there any easy way to compare them ledger style (compare 1st payment to 1st NSF, if they are the same ignore) and loop until it finds the 1st time when they do not match up.

Is there an easier way to do this? Should I be using some PHP with a more basic query?
Hi,

Does the date for NSF an PMT will be same?
Sep 20 '07 #7
amitpatel66
2,367 Expert 2GB
Hi,

Does the date for NSF an PMT will be same?
Try Below Query:

Expand|Select|Wrap|Line Numbers
  1. SELECT E.cid,E.ddate,E.amt,E.caty FROM 
  2. (SELECT j.*,ROW_NUMBER() OVER(PARTITION BY j.amt,j.caty ORDER BY j.CID) rn FROM jnl j) E
  3. WHERE E.rn > 1
  4.  
Sep 20 '07 #8
Hi,

Does the date for NSF an PMT will be same?
No, they would not be the same. An NSF might be within 7-10 days of a PMT.

The problem is, if they pay weekly, there could also be another PMT within that timeframe.
Sep 20 '07 #9
Try Below Query:

Expand|Select|Wrap|Line Numbers
  1. SELECT E.cid,E.ddate,E.amt,E.caty FROM 
  2. (SELECT j.*,ROW_NUMBER() OVER(PARTITION BY j.amt,j.caty ORDER BY j.CID) rn FROM jnl j) E
  3. WHERE E.rn > 1
  4.  
I think I am messing up the syntax somewhere. I'm not familiar with some of the functions you are using, here is what I tried to run:

SELECT e.clientid, e.effdt, e.amount, e.apply_to_category FROM (SELECT j.*, ROW_NUMBER() OVER(PARTITION BY j.amount,j.apply_to_category ORDER BY j.clientid) rn FROM client_journal j) client_journal e WHERE e.rn > 1;
Sep 20 '07 #10
amitpatel - can you give me any help with the syntax? Thanks!
Sep 27 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Karen | last post by:
I inserted this statement and it worked great for the customers that have no payment history, but for the customers that have a history and an open invoice, it still used today's date in the mix...
1
by: rahman | last post by:
I know it should be very easy but I am new in ASP so I could not figured out. Here is the simplified version of my code: thePaymentID= request.querystring("IDValue") SQLqueryPayment= "SELECT...
1
by: blabla120 | last post by:
Hi folks, I am net to NHibernate, and I hava a read baisc/general question. In my database (PostgreSQL), I have an unique index laying on the field transaktionsnummer which is located in the...
3
by: davidhumphrey70 | last post by:
Hi, I am in serious need of some help PLEASE? I have a 4 tables (April data, May data, June data and July data) with numerous fields. Each of the tables has its own "Passed for payment to...
0
by: ghostrider | last post by:
My program seems to slove for all the mortgages at once. And will not clear out the pane and accept another choice by the user. Can someone steer me in the right direction with this problem. My...
1
by: myemail.an | last post by:
Hi all, I am a novice to Access, and was wondering if I could get some help on a problem I can't solve. I have a database with customer payments, structured like this: customer code type of...
5
by: creative1 | last post by:
hi, I am new at writing JSP and Servlets. When I compile my serverlet I get follwoing error cannot find mymbol method parseDate(java.lang.String) I have follwoing code: Code: ( text )...
2
by: TriAdmin | last post by:
I am shopping for a payment processor for a subscription-based (recurring payment) website. I need it to be easy to implement and automate the recurring charges. I've review the details of...
0
by: Mrs Scilla Madlin | last post by:
This is to officially inform you that we have verified your contract/inheritance file presently on my desk, and I found out that you have not fulfilling the obligations giving to you in respect to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.