Skip to content

Instantly share code, notes, and snippets.

@zvrba
Created December 5, 2022 17:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save zvrba/2f694ee388c7b6d169ac4a431381f5a9 to your computer and use it in GitHub Desktop.
Multiple result sets
DECLARE @MasterObjects TABLE(Col1 INT, COL2 VARCHAR(24), ...)
INSERT INTO @MasterObjects
SELECT * -- Use only columns you need, not *
FROM MasterTable WHERE ID IN @MyIdList -- @MyIdList is table valued parameter populated with ids you want to pull
SELECT * -- Again only columns you need
FROM SideTable1
JOIN @MasterObjects ON ...
SELECT * -- Ditto
FROM SideTable2
JOIN @MasterObjects ON ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment