Generating Absurd Numbers Of Columns

Kevin Feasel



Brent Ozar wants to generate SmallInt.Max columns:

Alright, so we’ve learned that I can’t return more than 65,535 columns, AND I can only use 4,096 elements in my SELECT. I can think of several workarounds there – 65,535 / 4096 = about 16, which means I could create a few tables or CTEs and do SELECT *’s from them, thereby returning all 65,535 columns with less than 4,096 things in my SELECT. But for now, we’ll just start with 4,096 things in my SELECT:

If you think you need 65K columns returned, I refer you to Swart’s Ten Percent Rule.

Related Posts

T-SQL Join Delete

Steve Stedman walks us through a bit of T-SQL proprietary syntax: 1 2 3 DELETE t2 FROM [dbo].[Table1] t1 INNER JOIN [dbo].[Table2] t2 on t1.favColor =; Names have been changed to protect the innocent. In the above delete statement which table will have rows deleted from it? A: Table1 B: Table2 C: Both Table1 […]

Read More

Date And Time Functions To Avoid

Randolph West shares his thoughts on three functions he’d rather you avoid: CURRENT_TIMESTAMP is the ANSI-equivalent of GETDATE(). ANSI is an acronym for the American National Standards Institute, and sometimes vendors will include ANSI functions in their products so they can say that they’re ANSI-compliant (which is not a bad thing, in most cases). There are three main problems […]

Read More


August 2016
« Jul Sep »