I'm trying to migrate an app. from Access to SQL Server, and find that Transact-SQL does not support LAST/FIRST functions. Is there any alternative to these?
Below is the Access SQL statement:
SELECT Last(tblZoneNameString.Val) AS strZoneName, tblZoneNameString.TagIndex
FROM tblZoneNameString
GROUP BY tblZoneNameString.TagIndex
HAVING (((tblZoneNameString.TagIndex)>0));
Use MIN and MAX
Denis the SQL Menace
http://sqlservercode.blogspot.com/
|||In SQL Server 2005, you can do something like this: select tblZoneNameString.Val as strZoneName, tblZoneNameString.TagIndex from ( select tblZoneNameString.Val as strZoneName, tblZoneNameString.TagIndex, rank() over (partition by tblZoneNameString.TagIndex order by ?) as rk from tblZoneNameString ) as T where rk = 1 Where I've written ? you will need to put whatever column or columns answer the question "last in order of what?". Perhaps this is something like someDateTime DESC. Steve Kass Drew University JimNolandCBI@.discussions.microsoft.com wrote:
> I'm trying to migrate an app. from Access to SQL Server, and find that
> Transact-SQL does not support LAST/FIRST functions. Is there any
> alternative to these?
>
> Below is the Access SQL statement:
>
> SELECT Last(tblZoneNameString.Val) AS strZoneName,
> tblZoneNameString.TagIndex
> FROM tblZoneNameString
> GROUP BY tblZoneNameString.TagIndex
> HAVING (((tblZoneNameString.TagIndex)>0));
>
>
No comments:
Post a Comment