Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Table Variables

Author  Topic 

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2013-03-11 : 10:14:17
im using variable tables have the first part working the way i want
after the first part i need to use another table and the info from my temptable to get the data i need
here is my code
DECLARE @FirstTable TABLE
(
Fk_fund int,
Date datetime,
isin nvarchar(12),
Fundname ntext,
ShareCurrency nvarchar(3),
Pricepershare numeric,
exchanegRate numeric,
FirstSimulation nvarchar(20),
SecondSimulation nvarchar(20),
ThirdSimulation nvarchar (20)
)
INSERT INTO @FirstTable (Fk_fund, Date,isin,Fundname,ShareCurrency, Pricepershare,
exchanegRate,FirstSimulation,SecondSimulation,ThirdSimulation)
SELECT dp.Fk_fund ,
dp.Date ,
dp.isin ,
dp.Fundname,
dp.ShareCurrency ,
dp. Pricepershare ,
dp. exchanegRate ,
s.FirstSimulation ,
s.SecondSimulation ,
s.ThirdSimulation
FROM generic.DailyPrice dp
inner
join generic.Simulation s
on dp.ISIN =s.ISIN
where Date=
(SELECT MAX(Date) FROM generic.DailyPrice)

select * from generic.HistoricalPrice hp
inner
join @FirstTable
on hp.ISIN = @FirstTable.ThirdSimulation
where hp.Date > @FirstTable.date


its the last part im having trouble with
 select * from generic.HistoricalPrice hp
inner
join @FirstTable
on hp.ISIN = @FirstTable.ThirdSimulation
where hp.Date > @FirstTable.date

getting this error
Msg 137, Level 16, State 1, Line 39
Must declare the scalar variable "@FirstTable".
any ideas

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2013-03-11 : 10:28:01
got it this fixes it
select * from generic.HistoricalPrice hp
inner
join @FirstTable ft
on hp.ISIN = ft.ThirdSimulation
where hp.Date > ft.date
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-11 : 12:19:14
quote:
Originally posted by rjhe22

got it this fixes it
select * from generic.HistoricalPrice hp
inner
join @FirstTable ft
on hp.ISIN = ft.ThirdSimulation
where hp.Date > ft.date



this will cause a hidden RBAR and can hurt performance

Read this
http://www.sqlservercentral.com/articles/T-SQL/61539/

If you can lets us know your exact requirement we might be able to suggest an alternative

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -