Luis Cazares (12/15/2014)
This is an idea on how to do it. It's not perfect as the NULLS will be sorted first. I'm sure that you'll be able to handle that.
DECLARE @RowCount int;
SELECT TABLE_CATALOG
,TABLE_SCHEMA
,TABLE_NAME
,COLUMN_NAME
,ORDINAL_POSITION
INTO #Columns
FROM INFORMATION_SCHEMA.columns;
SET @RowCount = @@ROWCOUNT;
WITH cteShort(N) AS(
SELECT TOP(15 - (@RowCount % 15)) N
FROM(VALUES(NULL),(NULL),(NULL),(NULL),(NULL), --5
(NULL),(NULL),(NULL),(NULL),(NULL), --10
(NULL),(NULL),(NULL),(NULL),(NULL))e(N) --15
)
SELECT *
FROM #Columns
UNION ALL
SELECT NULL
,NULL
,NULL
,'~~~'
,NULL
FROM cteShort
ORDER BY TABLE_CATALOG DESC;
DROP TABLE #Columns;
Except that I believe the Table Row Constructor (VALUES) was introduced in SQL 2008.
Instead you can use something like this:
SELECT NULL UNION ALL SELECT NULL
... -- 11 more
UNION ALL SELECT NULL UNION ALL SELECT NULL
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St