Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Trying to Join two temp tables

$
0
0

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_Import_Parameters_Cash @RunDate = N'20180831', @StartDate = N'20180731', @PortfolioID = 0,@ReportGroupID = 1

 

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_Assets_Import_Parameters_Cash] @RunDate = N'20180831',@StartDate = N'20180731',@PortfolioID =0,@ReportGroupID = 1

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]



Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>