Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Select Last PaymentDay

Author  Topic 

kostaras
Starting Member

2 Posts

Posted - 2014-09-17 : 09:46:43
I have 2 tables: FightersInfo and PaymentInfo. 1 fighter got many payment days. I need help to select last payment day.

SELECT FName, LName, PaymentDay, PaymentDescr,PaymentAmount, Active
WHERE (PaymentAMount= 0
OR PaymentAmount = NULL
OR PaymentDay = NULL
OR "Last PaymentDay is before 1 month ago")
AND Active =1

i want to get only the Last payment of fighter if is before a month ... For example if a fighter has many payments only before a month i want the last payment But if a fighter has a lot payments before a month and gots a payment in last month i dont want him in my select

here is schema of my tables

[url]http://sqlfiddle.com/#!6/3d861/3[/url]

i want to return only the last PaymentDay of FighterID=1 Causes the FighterID=2 he paid in last month

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-09-17 : 20:10:49
your description and your sample data does not really matched.
Anyway, this will give you FighterID 1
and  DATEDIFF(month, LastPayment.PaymentDay, GETDATE()) >= 1



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -