daviegravy
Programmer
I need some help refining my query...
My query is..
Now my problem is I'm getting multiple records with the same OrderNumber and different SpecialID's. I need to refine that down to just getting the record with the MAX(SpecialID) for any particular RunbookID.
My results looks like...
I need just the last record returned. Can anyone help me subquery to get the desired results? Thank so much!
My query is..
Code:
SELECT dbo.DataEnrichmentRequirements.IEPOrderNumber, MAX(dcuser.RunBooks.ID) AS SpecialID, dcuser.RunBooks.RunBookName,
dbo.Client_overview.wfg_flowsheet, dbo.Client_overview.wfg_flow, dbo.DataEnrichmentRequirements.IBEEnvironmentProd,
dcuser.RunBooks.RunBookID
FROM dcuser.RunBooks INNER JOIN
dbo.Client_overview ON dcuser.RunBooks.OverviewID = dbo.Client_overview.OverviewID INNER JOIN
dbo.DataEnrichmentRequirements ON dcuser.RunBooks.RunBookID = dbo.DataEnrichmentRequirements.RunbookId
WHERE (dbo.DataEnrichmentRequirements.IEPOrderNumber IS NOT NULL) AND (dbo.DataEnrichmentRequirements.IBEEnvironmentProd = 'on')
GROUP BY dbo.DataEnrichmentRequirements.IEPOrderNumber, dbo.Client_overview.wfg_flowsheet, dcuser.RunBooks.RunBookName,
dbo.Client_overview.wfg_flow, dbo.DataEnrichmentRequirements.IBEEnvironmentProd, dcuser.RunBooks.RunBookID
Now my problem is I'm getting multiple records with the same OrderNumber and different SpecialID's. I need to refine that down to just getting the record with the MAX(SpecialID) for any particular RunbookID.
My results looks like...
Code:
OrderNumber SpecialID RunbookID Other Data....
10001 45 1067
10001 300 1067
10001 3450 1067
10001 5000 1067
I need just the last record returned. Can anyone help me subquery to get the desired results? Thank so much!