Author |
Topic |
Freaking_cute
Starting Member
4 Posts |
Posted - 2012-05-29 : 04:01:49
|
Hello All...please guide me how i get latest value of exchange rate.in details : i have a table named "Temp" who contain columns of exchange_rate,Start_date,end_date.and i want output like record_date :21-Feb-2012 exchange_rate : 0.3366but i want latest value of exchange_rate of February what should i do now???please need your reply as soon as possible |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2012-05-29 : 05:11:28
|
SELECT TOP(1) * FROM dbo.Temp WHERE StartDate <= '20120229' ORDER BY StartDate DESC N 56°04'39.26"E 12°55'05.63" |
|
|
Freaking_cute
Starting Member
4 Posts |
Posted - 2012-05-29 : 06:17:12
|
Thanks SwePeso.But i want latest record.i have just given you that date as a sample,it is not the actual one.like i have data like this Start_date :14-Feb-2007 end_date : 14-Mar-2007 Exchange_rate:0.336 Start_date :15-Feb-2007 end_date : 14-Apr-2007 Exchange_rate:0.663these are my table data.Now the output which i got isMonth exchange_rateFeb 0.336Mar 0.336Feb 0.663Mar 0.663April 0.663 Now you can see that here is Feb Twice time so i want latest exchange_rate value of Feb which is 0.663..so how i remove or delete the previous exchange_rate value or how i just display the latest value of Feb and also these type of month which comes multiple times |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2012-05-29 : 11:43:34
|
You want all months in one query? Or only one month?Your description is at minimum, unclear.DECLARE @Sample TABLE ( StartDate DATE NOT NULL, EndDate DATE NOT NULL, ExchangeRate SMALLMONEY NOT NULL )INSERT @SampleVALUES ('14-Feb-2007', '14-Mar-2007', 0.336), ('15-Feb-2007', '14-Apr-2007', 0.663)-- SwePesoSELECT DATENAME(MONTH, DATEADD(DAY, v.Number, s.StartDate)) AS theMonth, s.ExchangeRateFROM ( SELECT StartDate, DATEDIFF(DAY, StartDate, EndDate) AS Interval, ROW_NUMBER() OVER (ORDER BY StartDate) AS GrpID, ExchangeRate FROM @Sample ) AS sINNER JOIN master.dbo.spt_values AS v ON v.Type = 'P' AND v.Number BETWEEN 0 AND s.IntervalGROUP BY DATENAME(MONTH, DATEADD(DAY, v.Number, s.StartDate)), s.ExchangeRate, s.GrpIDORDER BY s.GrpID, MIN(v.Number) N 56°04'39.26"E 12°55'05.63" |
|
|
Freaking_cute
Starting Member
4 Posts |
Posted - 2012-05-29 : 14:25:22
|
Oh thanks a lot Swepose really!! :O you are Champ for me :)I will run this query tomorrow for sure and will let you know.Can you give me one solution more please??Actually i declared cursor and within cursor i declared a FOR loop but now within this session/cursor, i want to create a temporary(Temp) table that stores the output of my query so the question is how i declare Temp table by using oracle.i wrote within cursor like :Declare Global Temporary Table Temp(id int;Name varchar(5);)on commit preserve rows;the problem with above declaration is it is not creating temp table.Have you any idea about this??please kindly let me know as i am new also i have not enough knowlegde about SQL :( |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-29 : 14:33:38
|
you might be better off redirecting oracle questions to relevant forums like www.orafaq.comthis is ms sql server forum------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
Freaking_cute
Starting Member
4 Posts |
Posted - 2012-06-01 : 03:30:24
|
hey i am now again stuck in one problem please someone let me out from this..I have table named 'Temp' having columns EXCH_GRP_CODE,EXCH_RATES_CODE,CURRENCY_CODE,MONTH_NAME,YEAR_CODE,EXCH_RTand i got data/output after running one of my query is:outputEXCH_GRP_CODE,EXCH_RT_CODE,CURRENCY_CODE,MONTH_NAME,YEAR_CODE,EXCH_RTACT,ME,FI,DEC,2003,2.072ACT,CE,FI,DEC,2003,1.94ACT,AVG,FI,JAN,2004,0.95ACT,PE,FI,JAN,2004,0.91ACT,AVG,FI,FEB,2004,0.98ACT,PE,FI,FEB,2004,5.93ACT,AVG,FI,MAR,2004,6.48ACT,PE,FI,MAR,2004,5.99Now,how i get the updated records between same name of months like i need this record of dec:ACT,CE,FI,DEC,2003,1.94.mean latest record of dec 2003..please tell me the solutions?? |
|
|
|
|
|