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
 Last date

Author  Topic 

mjimenezh
Yak Posting Veteran

81 Posts

Posted - 2014-03-24 : 00:44:59
Hi, I have a SQL 2008 View that gives me the xrate of some date, I need that only shows me the xrate of most recent date How can I do this? here is my code
SELECT     TOP (100) PERCENT MAX(date_l) AS Date_l, rate_exchange AS XRate
FROM dbo.rates
GROUP BY date_l, rate_exchange
ORDER BY date_l DESC


Thanks in advance

Monib
Starting Member

11 Posts

Posted - 2014-03-24 : 02:18:35
Hi, I guess you are already taking maximum date from Date_1, If you want it from XRate, put Max funtion with that column and remove from group by. Stay Blessed

Monib
Go to Top of Page

mjimenezh
Yak Posting Veteran

81 Posts

Posted - 2014-03-24 : 02:23:40
Hi Monib, I was thinking that too but when I Execute it I'm receiving all the records not just the max date and I don't know why.

Thanks...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2014-03-28 : 06:35:11
Create your view with the following code

SELECT MAX(date_l) AS Date_l, rate_exchange AS XRate
FROM dbo.rates
GROUP BY rate_exchange


and do the ORDER BY when you query that view



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

mjimenezh
Yak Posting Veteran

81 Posts

Posted - 2014-03-28 : 15:04:47
Thank you so much Mandhivanan

Go to Top of Page
   

- Advertisement -