--USE FOR XML PATH - MUST BE SQL2005 OR HIGHER.
SELECT   'SELECT ' + '''' + so.Name +''', as TblName ' ,   (SELECT     sc.Name + ', ' AS 'data()'    FROM          dbo.SysColumns sc    WHERE      so.ID = sc.ID FOR XML Path('')) AS PARSESTRING  FROM         Sysobjects so where so.xtype = 'U'
 and so.name = 'mytablewithlotsofcolumns'
Then just finish it off with adding the from in the parser string.
Comment on other methods that you have used.
Friday, January 7, 2011
Subscribe to:
Comments (Atom)
 
 
