meadow0 (3/5/2013)
Hi Sean,The query itself works fine, I'm having an issue converting this into a temp table. I'm not even quite sure how temp tables work in theory, but I'm attempting to convert the functional query into a temp table.
I don't think I understand what you mean about converting a query into a temp table. Temp tables work just like a permanent table but they will go away when the connection it closed, or it is dropped.
You could have your original query generate and populate a temp table if you want quite easily.
SELECT A.Portfolio, B.PortfolioID, SUM(B.MarketValue) AS SumOfMV,
COUNT(B.SecID) AS [# of Securities]
INTO #YourTempTable
From ERTutAccounts A
INNER JOIN ERTutPositions B ON A.PortfolioID = B.PortfolioID
GROUP BY A.Portfolio, B.PortfolioID
HAVING COUNT(B.SecID) > 70 OR SUM(B.MarketValue) > 30000000
If you execute this you will now have a temp table called #YourTempTable that has the results of your above query. You can now treat it like any other table for the duration of your process.
--EDIT--
Misplaced quotes.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/