DECLARE @Xrate TABLE (xrProperty VARCHAR(2), xrDateTime DATETIME, xrXrate MONEY)
INSERT INTO @Xrate (xrProperty,xrXrate,xrDateTime)
SELECT 'CU'
,AVG(crr.ExchangeValue)
,DATEPART(YYYY,crr.ExchangeDate) + '-' + DATEPART(MM,crr.ExchangeDate) + '-01 00:00:00 000'
FROM dbo.CurrencyRates crr
WHERE crr.CurrencyFromId = (SELECT cur.id FROM dbo.Currencies cur WHERE cur.CODE = 'EUR')
AND crr.CurrencyToId = (SELECT cur.id FROM dbo.Currencies cur WHERE cur.CODE = 'USD')
AND crr.ExchangeDate > '2005-01-01'
GROUP BY 'CU',DATEPART(YYYY,crr.ExchangeDate) + '-' + DATEPART(MM,crr.ExchangeDate) + '-01 00:00:00 000'
SELECT * FROM @Xrate
|