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 2000 Forums
 SQL Server Development (2000)
 don't know how to do it

Author  Topic 

Rita Bhatnagar
Posting Yak Master

172 Posts

Posted - 2001-11-14 : 11:41:53
I have this query. no idea how to achieve this.I got idea from this forum how to get the Last function working but with too many LASTs is there any other way?
Thanks.
SELECT DISTINCT CareRecipient.CareRecipientEntityId AS CareRecipientId,
Last(IIf([adt].[IsAdmitted]=-1 Or [adt].[adtcodeid]=1
Or [adt].[adtcodeid]=4096 Or [adt].[adtcodeid]=256
Or [adt].[adtcodeid]=512 Or [adt].[adtcodeid]=2048,-1,0))
AS IsAdmitted, Last(ADT.ADTCodeID) AS ADTCodeID
FROM CareRecipient
INNER JOIN ADT
ON CareRecipient.CareRecipientId = ADT.eCareRecipientID
GROUP BY CareRecipient.CareRecipientEntityId
HAVING (((Last(ADT.ADTCodeID))=1 Or (Last(ADT.ADTCodeID))=4096
Or (Last(ADT.ADTCodeID))=256 Or (Last(ADT.ADTCodeID))=512
Or (Last(ADT.ADTCodeID))=2048))
ORDER BY CareRecipient.CareRecipientEntityId

   

- Advertisement -