Showing posts with label payment. Show all posts
Showing posts with label payment. Show all posts

Wednesday, March 21, 2012

Last payment is also a bigger payment

How to create such a query?
Please enter example here :SELECT * FROM TargetBleigh.Mind
seriously,
please let us have more information on what you are trying to acheive.
Is this meant to be a constraint, or a selection filter?
Mr Tea
"TargetBleigh" <ddsd*f.com> wrote in message
news:8a6dnU4VMNCDfYvfRVn-ug@.comcast.com...
> How to create such a query?
> Please enter example here :
>
>|||SELECTION FILTER
THANKS!|||Please read your specs, since we cannot read your mind. If you have a
series of paymetns of different sizes, then you can model each payment
coupon as a single row in a table, with a due date, actual payment
date, etc.|||This is meant to be a query. Not a row in a table, or a restraint.
That is why I used the word "query"|||Here's your query:
SELECT MAX(payment)
FROM table1
Enjoy
"TargetBleigh" <ddsd*f.com> wrote in message
news:nKydnc9MvZvOe4rfRVn-uw@.comcast.com...
> This is meant to be a query. Not a row in a table, or a restraint.
> That is why I used the word "query"
>
>|||That is great. I hope you use that on your resume.
Right at the top.|||Your "specification" is too vague for anyone to give you much help. The
following article explains the best way to get help with your problem
in this group. Please take the time to read it and follow the advice.
The more information you can give the better chance you have of getting
an accurate and useful response.
http://www.aspfaq.com/etiquette.asp?id=5006
David Portas
SQL Server MVP
--|||I don't see how there could be more than one theory about what I meant by my
post.
I need a query that returns all records where the last payment is also the
biggest payment in a given set.
I could jump thru all kinds of hoops including posting data and DDL, but
come on - wouldn't it be easier for those of you who want to help for you
to just imagine a table with dates and dollars?
Do you really need someone to explain that part to you?
Do you absolutely have to think that way?
Please think harder, or at least don't obstruct my thread with answers that
are not answers.
Thanks.|||This is a free forum where people voluntarily give their time to help
others. If you aren't prepared to "jump through a few hoops" then why
should anyone else? No matter. Your responses have probably guaranteed
that everyone will pass this one by anyway.
David Portas
SQL Server MVP
--

Monday, March 12, 2012

Last Function

SQL Server has no Last() and Max() pulls the Max not the last. Is there a way to pull the Last payment amount with the date of that payment, in SQL Server??

tblClients - ClientID (PK)
tblPayments - PaymentID (PK)

Thanks for any help,You can add a timestamp column to the table and then use Max(TimestampCol) to return the last inserted record (which i assume you want to return), e.g.


SELECT
*
FROM
myTable
WHERE
myTable.TimestampCol = (SELECT Max(TimestampCol) FROM myTable)
|||You're going to have to date stamp your transactions.

Last and Previous Query

I'm kindof at a lose for how to ask my database to show me the last payment amount and payment date for clients and also show me the previous payment amount and payment date for clients based on a date range.

Could anyone offer any pointers or examples?

Thank you very much.

We could use a very simple table and field setup like this just so you could show an example:

tblClient
Client_ID

tblOrder
Order_ID
Client_ID

tblOrderPayments
Payment_ID
Order_ID
Client_ID
PaymentDate
PaymentAmountLookup aggregates such as MAX and check out TOP.|||I looked them up but the only thing is that most examples are of there simplist use. So getting the max is easy but then getting the payment just prior to that is another thing all together. If anyone can offer any suggestions, I thank you,|||Well one way, and they'll be others, would be to get the latest set and store them in a table var. Then run the same query again except you exclude those you found in the first. Now you can do that all in 1 batch but the syntax can get a bit confusing. I like table vars, sure they're not optimal but they do make the SQL nice and easy. Once you get it working you can always optimise out the table var.