Link to home
Create AccountLog in
Microsoft SQL Server 2005

Microsoft SQL Server 2005

--

Questions

--

Followers

Top Experts

Avatar of Steven O'Neill
Steven O'Neill🇬🇧

Need to perform a MAX on a date field
I have a SQL statement that I'm looking to be able to perform a MAX upon a date field. The code I currently have is below and it will produce a list of everything I need but I only need to see the last update if all the other fields match up.

Basically I think I need to perform a MAX on the dbo.PS_Business_Base.Created field but if I add a Group By clause to the query then it breaks so I'm assuming I need to take the Grouping out a level to allow the grouping to take place first and then perform the usual SELECT.

Any ideas would be appreciate as always guys.
SELECT     dbo.PS_Business_Base.Name AS [Business Name], dbo.PS_Business_Base.Region, dbo.PS_Application_Base.ProductType AS [Type of Funding], 
                      dbo.PS_Application_Base.LoanAmountApproved AS [Loan Amount], dbo.PS_Application_Base.GrantAmountApproved AS [Grant Amount], 
                      dbo.PS_Application_Base.PeriodOfLoan AS [Period of Loan], 
                      dbo.PS_Application_Base.DeferredInitialRepaymentPeriod AS [Deferred Initial Repayment Period], 
                      dbo.PS_Application_Base.InterestOnlyPeriod AS [Interest Only Period], dbo.PS_Application_Base.PanelDate AS [Panel Date], 
                      dbo.PS_Application_Base.ApprovedDate AS [Approved Date], dbo.PS_Control.ValidationMessages AS [Validation Messages], 
                      dbo.PS_Control.ProposalCreationMessages AS [Proposal Creation Messages], dbo.PS_Control.Completed AS [Process Date], 
                      dbo.PS_Control.Reference, dbo.PS_Application_Base.ApplicationGUID, dbo.PS_Control.UpdateType, dbo.PS_Control.ProcessFlag, 
                      dbo.PS_Business_Base.Created AS [Date Created]
FROM         dbo.PS_Application_Base INNER JOIN
                      dbo.PS_Business_Application_Link INNER JOIN
                      dbo.PS_Business_Base ON dbo.PS_Business_Application_Link.BusinessGUID = dbo.PS_Business_Base.BusinessGUID ON 
                      dbo.PS_Application_Base.ApplicationGUID = dbo.PS_Business_Application_Link.ApplicationGUID INNER JOIN
                      dbo.PS_Control ON dbo.PS_Application_Base.ApplicationGUID = dbo.PS_Control.Reference
WHERE     (dbo.PS_Control.UpdateType = 0) AND (dbo.PS_Control.ProcessFlag <> 0) AND (dbo.PS_Control.ProcessFlag <> 10)

Open in new window

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


ASKER CERTIFIED SOLUTION
Avatar of Raja Jegan RRaja Jegan R🇮🇳

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of Steven O'NeillSteven O'Neill🇬🇧

ASKER

Appears to work a charm. Wasn't aware of OVER or PARTITION so this is ideal.

Avatar of Raja Jegan RRaja Jegan R🇮🇳

Welcome..
And glad to help you out..

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

Microsoft SQL Server 2005

Microsoft SQL Server 2005

--

Questions

--

Followers

Top Experts

Microsoft SQL Server 2005 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. It includes support for managing XML data and allows a database server to be exposed over web services using Tabular Data Stream (TDS) packets encapsulated within SOAP (protocol) requests.