Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Latest Date to be returned

Author  Topic 

masond
Constraint Violating Yak Guru

447 Posts

Posted - 2013-12-10 : 05:42:09
HI All

I need some help
Aim – Get the latest [hst_date_processed] for every [hst_merchnum]
My query so far is

SELECT top 5
[hst_merchnum]
,[hst_date_processed]
FROM [FDMS].[dbo].[Fact_Financial_History]
where hst_merchnum = '878001897'
group by [hst_merchnum],hst_date_processed

which return the following results

hst_merchnum hst_date_processed
878001897 2011-12-01
878001897 2012-07-01
878001897 2011-11-01
878001897 2011-02-01
878001897 2011-05-01

However results i need are ;
hst_merchnum hst_date_processed
878001897 2012-07-01

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-12-10 : 05:45:43
[code]
SELECT [hst_merchnum]
,MAX([hst_date_processed]) AS LatestProcessedDate
FROM [FDMS].[dbo].[Fact_Financial_History]
where hst_merchnum = '878001897'
group by [hst_merchnum]
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 2013-12-10 : 05:50:19
HI visakh16
Thats great for individual merchant, what happens when i want to search the whole database ?
Would Max function still work ?
Go to Top of Page
   

- Advertisement -