Hi there, I have the following query that executes 2 stored procs and creates 2 seperate temp tables: #temptable3 & #temptot.
What I'd like to do is do a Cross Join of #temptable3 to #temptot by [Portfolio Code] AND [Valuation Date] so that for each [Portfolio Code] and each [Valuation Date] I can cross-check their market values.
I've tried the code below but I get the following error:
Error code:
Msg 208, Level 16, State 0, Line 52
Invalid object name '#temptable3'
Here is the code for the Join is at the end:
USE [DataWarehouse]
--SELECT HOL EXTRACT, SUM DAILY INDIVIDUAL INSTRUMENT MV TO GET DAILY TOTAL PORTFOLIO MV
CREATE TABLE #temptable3
(
[Portfolio Code] INT,
[Valuation Date] DATETIME,
[Instrument Code] VARCHAR(20),
[Quantity] float,
[Market Value] float,
[Book Value] float,
[Price] float,
[Instrument Long Name] VARCHAR(712),
[Instrument Short Name] VARCHAR(50),
[Risk Currency Exchange Rate] FLOAT,
[Accrued Interest] FLOAT,
[Effective Exposure] FLOAT,
[Modified Duration] FLOAT,
[Maturity Date] DATETIME,
[Duration] FLOAT
)
INSERT INTO #temptable3
EXEC dbo.EXTRACT_Statpro_Holdings_
SELECT
[Portfolio Code],[Valuation Date],sum([Market Value]) as TOT
FROM #temptable3
GROUP BY [Portfolio Code],[Valuation Date]
Order By [Portfolio Code],[Valuation Date]
DROP TABLE #temptable3
--SELECT TOT EXTRACT
CREATE TABLE #temptot
(
[Portfolio Code] INT,
[Valuation Date] DATETIME,
[All In Market Value] float,
[Units] float,
[Nav Price] float
)
INSERT INTO #temptot
EXEC [dbo].[EXTRACT_Statpro_Total_
SELECT
[Portfolio Code],[Valuation Date],[All In Market Value]
FROM #temptot
Order By [Portfolio Code],[Valuation Date]
DROP TABLE #temptot
--JOIN TABLES
Select p.[Portfolio Code],p.[Valuation Date],p.TOT,q.[Portfolio Code],q.[Valuation Date],q.[All In Market Value]
from #temptable3 as p inner join #temptot as q
on p.[Portfolio Code]=q.[Portfolio Code]