This tip not only for list the columns for single table,
we can get the columns for CTE and Sub Query too.
Fox example, Our CTE or SubQuery returning multiple columns and we need to apply some calculations or conversions on particular columns,then definitely we need to type all the column names then we need to apply the changes on particular column.
But using this we can select the query and follow the TIP to get the list of columns.
Sample Query:
--EX:1
WITH CTE AS (
SELECT SP.name , SC.text
FROM sysCOMMENTS SC
INNER JOIN sys.procedures SP ON SC.id = SP.object_id
)
SELECT * FROM CTE
--EX:2
SELECT *
FROM (
SELECT SP.name , SC.text
FROM sysCOMMENTS SC
INNER JOIN sys.procedures SP ON SC.id = SP.object_id
) AS A
commented on Jul 17 2012 12:25AM