SELECT top n from a Group

Posts   
 
    
TopDog74
User
Posts: 40
Joined: 27-Apr-2012
# Posted on: 12-Nov-2015 14:46:27   

Hi,

I have a requirement to select the most recent currency exchange rate records for a list of specific currencies, based on an exchange date, from a table which holds a list of historic currency exchange rates for every currency.

I have a procedure which does this like so:

;WITH currencyRateExpression AS ( SELECT *, ROW_NUMBER() OVER (PARTITION BY c.CUR_ID ORDER BY c.CRH_DateEffective DESC) AS cre FROM CURRHISTORY c WHERE c.[CRH_DateEffective] <= '2015-02-02T11:40:18' AND c.CUR_ID IN ('EUR', 'SGD', 'USD' )

) SELECT * FROM currencyRateExpression WHERE cre = 1

My question is, is there a way to write this in QuerySpec, and if so could you give me an example please?

Thanks, Iain

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Nov-2015 06:59:05   

Hi Iain,

This is not supported to write it in a QuerSpec, nor LLBLGen API. It's possible to rewrite it in another sql form, but I think your code would be more efficient. My advise: keep this in to a Stored procedure that you can call from code, even map it to a resulset.

David Elizondo | LLBLGen Support Team
TopDog74
User
Posts: 40
Joined: 27-Apr-2012
# Posted on: 13-Nov-2015 10:54:47   

Cool, that's what i did. Thanks for the quick response.