please explain select addressline1, city from person.address where isnumeric (postalcode)=1 and cast(cast(postalcode as int)as char )>'9000'?
Here's the formatted code that Dave_Green posted...
DECLARE @T TABLE (RateCode CHAR(2), Rate INT, LastModified DATETIME) INSERT @T VALUES ('01', 10, '2008-12-10 23:00'), ('01', 20, '2009-12-10 23:00'), ('01', 30, '2010-12-10 23:00'); WITH LastModifiedDate (RateCode, CurrentRate, PreviousModified) AS ( SELECT a.RateCode, a.Rate CurrentRate, MAX(b.LastModified) AS PreviousModified FROM @T a LEFT JOIN @t b ON a.ratecode = b.ratecode AND a.LastModified > b.LastModified GROUP BY a.Rate, a.RateCode, a.LastModified ) SELECT LastModifiedDate.RateCode, LastModifiedDate.CurrentRate, z.Rate PreviousRate FROM LastModifiedDate LEFT JOIN @T z ON z.RateCode = LastModifiedDate.RateCode AND LastModifiedDate.PreviousModified = z.LastModified ORDER BY LastModifiedDate.CurrentRate DESC
17 People are following this question.