Re: help with query please!!! max() and joins
From: Joe Scalise (jscalise_at_advantageccs.org)
Date: 10/26/04
- Next message: Aaron [SQL Server MVP]: "Re: Scope_Identity syntax question"
- Previous message: Steven Richardson: "Select statement"
- In reply to: Joe Scalise: "Re: help with query please!!! max() and joins"
- Next in thread: Adam Machanic: "Re: help with query please!!! max() and joins"
- Reply: Adam Machanic: "Re: help with query please!!! max() and joins"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 26 Oct 2004 12:04:19 -0400
actually it still pulls up the refunds.....
thats strange
"Joe Scalise" <jscalise@advantageccs.org> wrote in message
news:uo2UxQ3uEHA.3828@TK2MSFTNGP12.phx.gbl...
> Adam your the man...
>
> So far it looks as if it's exactly what i want! Yeah you are right
> PromiseStatus shouldn't be up there, it was only there because i had
> originally intended not to exclude those clients, but notate that they had
> a promise graphically in Reporting Services, like changing a box to red if
> they had a promise....
>
> what does the r1 do an mean?
>
> Thanks again for your help Adam!
> Anyway to rate you as a poster or MVP?
> "Adam Machanic" <amachanic@hotmail._removetoemail_.com> wrote in message
> news:etxvoJ3uEHA.1616@TK2MSFTNGP10.phx.gbl...
>> "Joe Scalise" <jscalise@advantageccs.org> wrote in message
>> news:uOrWU72uEHA.2520@TK2MSFTNGP15.phx.gbl...
>>>
>>> To rephrase what i need Adam: clients can have multiple rows in the
>> receipts
>>> table. For each client I want to grab the row with the most recent
>>> [DateReceived] fields as long as [PaymentType] <> REFUND, ALSO these
>> clients
>>> cannot be in the PaymentPromises table. The max function gives me
>>> results
>>> like this:
>>
>>
>> (untested):
>>
>> SELECT
>> dbo.Clients.ClientID,dbo.Clients.WholeName,dbo.PaymentPromises.PromiseStatus
>> ....
>> FROM clients
>> INNER JOIN receipts ON clients.clientid = receipts.clientid
>> LEFT OUTER JOIN dbo.PaymentPromises ON dbo.Clients.ClientID =
>> dbo.PaymentPromises.ClientID
>> WHERE receipts.paymenttype <> 'REFUND'
>> AND receipts.datereceived =
>> (SELECT MAX(datereceived)
>> FROM receipts r1
>> WHERE r1.clientid = receipts.clientid)
>> AND dbo.PaymentPromises.ClientID IS NULL
>>
>>
>> This should give you: Most recent receipt per client, unless that
>> receipt
>> was a refund, and only clients with no rows in the PaymentPromises table.
>> What I am confused about is why you have PaymentPromises in the SELECT
>> list
>> if you don't want clients to have rows in that table?
>>
>>
>> --
>> Adam Machanic
>> SQL Server MVP
>> http://www.sqljunkies.com/weblog/amachanic
>> --
>>
>>
>
>
- Next message: Aaron [SQL Server MVP]: "Re: Scope_Identity syntax question"
- Previous message: Steven Richardson: "Select statement"
- In reply to: Joe Scalise: "Re: help with query please!!! max() and joins"
- Next in thread: Adam Machanic: "Re: help with query please!!! max() and joins"
- Reply: Adam Machanic: "Re: help with query please!!! max() and joins"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|