This is not pretty, but you can do the following. Wrap the original query in a cte (commenting out the final ORDER BY if the query returns an ordered result set) and use that cte to do a SELECT INTO into a temp table WHERE 1=0. Because of the
1=0, the query will run without looking at any data, so it will be very fast. Then you can use INFORMATION_SCHEMA.COLUMNS on the temp table. For example, suppose your query is
use AdventureWorks2008R2
go
SELECT p.BusinessEntityID, p.Title, p.FirstName, p.MiddleName, p.LastName, p.Suffix, pp.PhoneNumber, pnt.Name AS PhoneNumberType, ea.EmailAddress,
p.EmailPromotion, at.Name AS AddressType, a.AddressLine1, a.AddressLine2, a.City, sp.Name AS StateProvinceName, a.PostalCode,
cr.Name AS CountryRegionName
FROM Person.Person AS p INNER JOIN
Person.BusinessEntityAddress AS bea ON bea.BusinessEntityID = p.BusinessEntityID INNER JOIN
Person.Address AS a ON a.AddressID = bea.AddressID INNER JOIN
Person.StateProvince AS sp ON sp.StateProvinceID = a.StateProvinceID INNER JOIN
Person.CountryRegion AS cr ON cr.CountryRegionCode = sp.CountryRegionCode INNER JOIN
Person.AddressType AS at ON at.AddressTypeID = bea.AddressTypeID INNER JOIN
Sales.Customer AS c ON c.PersonID = p.BusinessEntityID LEFT OUTER JOIN
Person.EmailAddress AS ea ON ea.BusinessEntityID = p.BusinessEntityID LEFT OUTER JOIN
Person.PersonPhone AS pp ON pp.BusinessEntityID = p.BusinessEntityID LEFT OUTER JOIN
Person.PhoneNumberType AS pnt ON pnt.PhoneNumberTypeID = pp.PhoneNumberTypeID
WHERE (c.StoreID IS NULL)
ORDER BY CountryRegionName, StateProvinceCode, City;
you can do
;WITH cte AS
(SELECT p.BusinessEntityID, p.Title, p.FirstName, p.MiddleName, p.LastName, p.Suffix, pp.PhoneNumber, pnt.Name AS PhoneNumberType, ea.EmailAddress,
p.EmailPromotion, at.Name AS AddressType, a.AddressLine1, a.AddressLine2, a.City, sp.Name AS StateProvinceName, a.PostalCode,
cr.Name AS CountryRegionName
FROM Person.Person AS p INNER JOIN
Person.BusinessEntityAddress AS bea ON bea.BusinessEntityID = p.BusinessEntityID INNER JOIN
Person.Address AS a ON a.AddressID = bea.AddressID INNER JOIN
Person.StateProvince AS sp ON sp.StateProvinceID = a.StateProvinceID INNER JOIN
Person.CountryRegion AS cr ON cr.CountryRegionCode = sp.CountryRegionCode INNER JOIN
Person.AddressType AS at ON at.AddressTypeID = bea.AddressTypeID INNER JOIN
Sales.Customer AS c ON c.PersonID = p.BusinessEntityID LEFT OUTER JOIN
Person.EmailAddress AS ea ON ea.BusinessEntityID = p.BusinessEntityID LEFT OUTER JOIN
Person.PersonPhone AS pp ON pp.BusinessEntityID = p.BusinessEntityID LEFT OUTER JOIN
Person.PhoneNumberType AS pnt ON pnt.PhoneNumberTypeID = pp.PhoneNumberTypeID
WHERE (c.StoreID IS NULL)
--ORDER BY CountryRegionName, StateProvinceCode, City
)
SELECT *
INTO #TempQuery
FROM cte
WHERE 1=0;
SELECT OBJECT_ID(c.TABLE_NAME, 'tempdb'), *
FROM tempdb.INFORMATION_SCHEMA.COLUMNS c
INNER JOIN tempdb.sys.tables t ON c.TABLE_NAME = t.name
WHERE OBJECT_ID('tempdb..#TempQuery') = t.object_id
go
Drop Table #TempQuery;
to get the information about the result columns from your query.
Tom