Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

SQL syntax best practice

$
0
0

If I can find the Most recent address using:

SELECT DISTINCT A.ClientKey, A.AdmissionKey, A.Address, A.CITY, A.State, A.ZIP, A.PhoneH, A.PhoneW, A.PhoneC
FROM         (SELECT     ClientKey, AdmissionKey, CONVERT(varchar, ISNULL(Date_Change, 1), 120) + CAST(DOCid AS varchar) AS DateKey, Address, CITY, State, ZIP,
                                              PhoneH, PhoneW, PhoneC
                       FROM          ClientAddressTable) AS A INNER JOIN
                          (SELECT     ClientKey, AdmissionKey, MAX(CONVERT(varchar, ISNULL(Date_Change, 1), 120)+ CAST(DOCid AS varchar)) AS MaxDateKey
                            FROM          ClientAddressTable AS ClientAddressTable_1
                            GROUP BY ClientKey, AdmissionKey) AS B ON A.AdmissionKey = B.AdmissionKey AND A.DateKey = B.MaxDateKey

What is the best way to find all Addresses EXCEPT the most recent?



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>