June 6, 2006 at 9:14 am
new to t-sql and having trouble with a query in my personal DB
i have a DB with stock prices, bond prices and just imported a new table with inflation data. i want to look at bond prices and CPI data for the same years
this is my draft query
select
b.close_price, b.date, c.avg, c.year from tenyearbond b inner join cpi c on datepart(year, (select date from tenyearbond)) = c.year
the cpi table is only a year and the 10 year bond table is the year, month and day. i get an error that the subquery returned more than one result. can someone help me out and point me to where this is in BOL so i can read up on it?
June 6, 2006 at 9:21 am
This should do it:
select b.close_price, b.date, c.avg, c.year
from tenyearbond b
inner join cpi c
on datepart(year, b.tenyearbond) = c.year
Performance won't be fantastic because if you have an index on tenyearbond.date, it won't be used.
John
June 6, 2006 at 9:45 am
thanks, works perfectly
i changed it a little and here is the final one i'm using
select
b.close_price, b.date, c.inflation, c.year
from tenyearbond b
inner join cpi c
on datepart(year, b.date) = c.year order by date
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply