SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Last date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mjimenezh
Yak Posting Veteran

Mexico
61 Posts

Posted - 03/24/2014 :  00:44:59  Show Profile  Reply with Quote
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

Pakistan
11 Posts

Posted - 03/24/2014 :  02:18:35  Show Profile  Reply with Quote
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

Mexico
61 Posts

Posted - 03/24/2014 :  02:23:40  Show Profile  Reply with Quote
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...

Edited by - mjimenezh on 03/24/2014 02:24:33
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22755 Posts

Posted - 03/28/2014 :  06:35:11  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

Mexico
61 Posts

Posted - 03/28/2014 :  15:04:47  Show Profile  Reply with Quote
Thank you so much Mandhivanan

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000