January 18, 2009 at 1:34 pm
I thought it might be interesting to create a consolidated Tips and Tricks thread. These should be time-savers or little known methods/techniques of doing things. Short descriptions are all that are needed for this thread, but if you have a backup article or site that further fleshes out the technique you are demonstrating, by all means include it. Many of these will be known to devoted readers of these forums, but the idea is for everyone to pick up something they may never have seen before, or be reminded of something they may have forgotten. If this thread gets enough good content, it could possibly be turned into an article (or a series of articles).
January 18, 2009 at 1:53 pm
I'll start it off with one that is fairly basic but many may not know about.
Creating a temp / staging table that mirrors a real table for data selection.
SELECT *
INTO #StagingTable
FROM myRealTable
WHERE 1=2
Due to the WHERE clause(1 will never equal 2), no rows will be selected, but the table will still be created, and will match the definition of your base table. I use this technique occasionally when I need to insert into one table using IF statements. You cannot use SELECT INTO #StagingTable multiple times within a stored procedure, even if the calls are inside two different IF statements (or an IF/ELSE) that are exclusive. This allows you to use INSERT INTO #StagingTable to circumvent that.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply