Have you ever needed to store the results of a complex query in a temp table? How did you go about working out what the definition for that temp table should be, the columns and their data types?
It can be a bit of a pain, not to mention time consuming to have to go figuring out what all datatypes of the base tables are.
I got fed up with all that hunting around as well so as a quick blog I thought I’d share a little script that will take your query in a variable and print out a temp table definition for its result set.
Click through for the script, as well as an important comment by frequent curatee Shane O’Neill.