SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Table Variables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rjhe22
Constraint Violating Yak Guru

251 Posts

Posted - 03/11/2013 :  10:14:17  Show Profile  Reply with Quote
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

251 Posts

Posted - 03/11/2013 :  10:28:01  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 03/11/2013 :  12:19:14  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000