June 13, 2014 at 10:22 am
TheGreenShepherd (6/13/2014)
Yep, exactly. Thanks.
Glad it worked. FYI, I did have to make some modify your inserts a bit to get things working. You should see the differences by comparing my code to what you had posted.
June 13, 2014 at 10:24 am
Yeah, thanks. This isn't like my production code. I was just trying to generalize an example while I was on the train home from work. Sorry if it wasn't perfect. I appreciate your help.
June 13, 2014 at 10:25 am
Lynn Pettis (6/13/2014)
jfogel (6/13/2014)
Ah, I see. Once I remarked out two of the select statements in Lynn's query before the cross apply I see just the desired result. Much more graceful method than mine.The first two selects were to display the initial data after the inserts. I used that to do a visual verification of my results.
I got that. I'm just not even sure what I was thinking. The whole question was how to do it without dynamic SQL and I turn around and propose something based on just that. I'm going to try and avoid touching anything important today!
Cheers
June 13, 2014 at 10:49 am
jfogel (6/13/2014)
Lynn Pettis (6/13/2014)
jfogel (6/13/2014)
Ah, I see. Once I remarked out two of the select statements in Lynn's query before the cross apply I see just the desired result. Much more graceful method than mine.The first two selects were to display the initial data after the inserts. I used that to do a visual verification of my results.
I got that. I'm just not even sure what I was thinking. The whole question was how to do it without dynamic SQL and I turn around and propose something based on just that. I'm going to try and avoid touching anything important today!
I know how you feel.
June 16, 2014 at 1:55 am
Another use of LEAD function
SELECT QueueId,TaskId,TaskName,Rundatetime FROM(
SELECT T.QueueId,T.TaskId,T.TaskName,T.RunDateTime, LEAD(taskid,MaximumQueueLength)OVER(PARTITION BY T.QueueId ORDER BY taskid DESC)lid FROM Tasks T
INNER JOIN Queue Q ON T.QueueId=Q.QueueId
)T1 WHERE lid IS NULL ORDER BY TaskName
EDIT: Works with SQL Server 2012 and above
--------------------------------------------------------------------------------------------------
I am just an another naive wannabe DBA trying to learn SQL Server
Viewing 5 posts - 16 through 19 (of 19 total)
You must be logged in to reply to this topic. Login to reply