Back from Florida. It was a good trip – though we forgot just how hot it is down there in the summer. I got to spend 8 hours cooking barbecue chickens for my old fire department’s Fourth of July parade – it was a great time, and I’ll talk some more about that later.
But one of my coworkers swung by and asked a very simple question – how do you get the results of a stored procedure (that returns a result set) into a table that you can query or join or use somewhere else? The simplest way is that temp tables are your friend, and you just insert the results into your temp table:
CREATE PROC test_proc
SET NOCOUNT ON
SELECT TOP 10 id, name FROM employee
CREATE TABLE #tmp(
INSERT INTO #tmp
With that, you can now treat the temp table like any other table:
Just don’t forget to clean up when you are done!
DROP TABLE #tmp