March 3, 2011 at 11:27 am
Hi this is table values
Investigation_IdCase_IdInvestigation_NoteDateTimeTeam_IdStatus_Id
31101050282Testing Testing Testing 2011-01-26 11:45:00.000 2 1
51101050282sample 2011-01-26 00:00:00.000 3 2
91102010093fdsafsadfasd2011-02-03 00:00:00.000 2 2
111102010093rffas rffas rffas rffas 2011-04-05 00:00:00.000 1 2
131101050215retst fasfsdaf 2011-04-05 00:00:00.000 2 1
I need output like
Investigation_IdCase_IdInvestigation_NoteDateTime Team_Id Status_Id
31101050282Testing Testing 2011-01-26 11:45:00.000 2 1
111102010093rffas rffas rffas rffas 2011-04-05 00:00:00.000 1 2
131101050215retst fasfsdaf 2011-04-05 00:00:00.000 2 1
I need results like caseid which is recently updated.
March 3, 2011 at 11:45 am
You could use a cte with ROW_NUMBER() OVER (PARTITION BY Case_Id ORDER BY DateTime DESC) and then query for row=1.
March 3, 2011 at 11:47 am
i think using the row_number function is the right way to tackle this; note i went to the trouble of putting your data into a consumable format; It helps you in the future if you can provide the data like taht so others can base their volunteer test scripts on it:
With MyCTE(Investigation_Id,Case_Id,Investigation_Note,DateTime,Team_Id,Status_Id)
AS
(
SELECT 3,'1101050282','Testing Testing Testing','2011-01-26 11:45:00.000','2','1' UNION ALL
SELECT 5,'1101050282','sample','2011-01-26 00:00:00.000','3','2' UNION ALL
SELECT 9,'1102010093','fdsafsadfasd','2011-02-03 00:00:00.000','2','2' UNION ALL
SELECT 11,'1102010093','rffas rffas rffas rffas','2011-04-05 00:00:00.000','1','2' UNION ALL
SELECT 13,'1101050215','retst fasfsdaf','2011-04-05 00:00:00.000','2','1'
),
AddingRowNum AS
(
SELECT
row_number() OVER (PARTITION BY Case_Id ORDER BY Case_Id,DateTime DESC) AS RW ,
* FROM MYCTE
)
SELECT * FROM AddingRowNum WHERE RW = 1
ORDER BY Investigation_Id
Lowell
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply