Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing MS Access 'Last' function

Status
Not open for further replies.

rbruder

Programmer
Feb 5, 2003
5
US
Hey folks,

I searched through the previous threads on this subject and just have been unable to get the right combination of 'group by' and joins to get the expected results in SQL Server2K. Here is the SQL string that worked in MS Access. Can anyone offer any guidance to get this to work in SQL Server?

SELECT Parcel.UserDefinedID, Last(Parcel.ParcelID) AS ParcelID, Parcel.TaxYear AS MaxTaxYear INTO _MaxTaxYearOut FROM Parcel


Thank you in advance,


Ron
 
Do you have any datetime field in your table. And also the thing is that how do you or on what basis do you determine the last ParcelID

try something like this:

SELECT TOP 1 Parcel.UserDefinedID, Parcel.ParcelID, Parcel.TaxYear AS MaxTaxYear INTO _MaxTaxYearOut FROM Parcel ORDER BY yourdatetimefield DESC

-L
 
Lothario,

I apologize for not posting the entire string, here it is:

SELECT Parcel.UserDefinedID, Last(Parcel.ParcelID) AS ParcelID, Parcel.TaxYear AS MaxTaxYear INTO _MaxTaxYearOut FROM Parcel WHERE (((Parcel.TaxYear)= 2004) AND ((Parcel.IsRE)=1)) GROUP BY Parcel.UserDefinedID, Parcel.TaxYear HAVING ((Left([Parcel].[UserdefinedID],3)='006')) ORDER BY Parcel.TaxYear DESC


Ron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top