March 30, 2010 at 8:45 am
Okay... I'm stuck. 🙁
Does anyone know how to get around / convert an Access Last function to SQL Server? I have the following query that I need to convert.
SELECT OPERATION_SCHED.SCHEDULE_ID, OPERATION_SCHED.RESOURCE_ID, OPERATION_SCHED.WORKORDER_BASE_ID,
OPERATION_SCHED.WORKORDER_SUB_ID,
Last(OPERATION_SCHED.SEQUENCE_NO) AS LastOfSEQUENCE_NO,
Last(DATEADD(d, 0, DATEDIFF(d, 0, [FINISH_DATE])) AS FINISH,
OPERATION_SCHED.WORKORDER_LOT_ID, OPERATION_SCHED.WORKORDER_SPLIT_ID
FROM OPERATION_SCHED
GROUP BY OPERATION_SCHED.SCHEDULE_ID, OPERATION_SCHED.RESOURCE_ID, OPERATION_SCHED.WORKORDER_BASE_ID,
OPERATION_SCHED.WORKORDER_SUB_ID, OPERATION_SCHED.WORKORDER_LOT_ID, OPERATION_SCHED.WORKORDER_SPLIT_ID
ORDER BY OPERATION_SCHED.WORKORDER_BASE_ID;
April 10, 2010 at 1:00 pm
last() returns the last row of a result set - doesn't it?
A brute force solution would be to select top 1 blah-blah-blah order by blah-blah DESC
_____________________________________
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at Amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.April 10, 2010 at 1:46 pm
"Last(..)" returns the last vaule according to what ordering criteria? You do not specify any ordering criteria that could apply to a LAST(..) aggregate function, and by definition, SQL has no default or implicit ordering.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
April 11, 2010 at 10:20 am
Please see the following (very short) thread:
http://www.sqlservercentral.com/Forums/Topic893987-149-1.aspx
I posted three ways to emulate the LAST function there.
Paul
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply