This article explains that how to generate SELECT statement with all the table columns.
In the Production environment, most of the tables will have more than 100 columns. If those tables are used in a report with all the columns then it will be difficult to type all the columns.
To ease the process, we can generate the SELECT statement and can use that for any purpose.
Use the below code and pass the table which you want to use in the SELECT statement.
In this example, I used FactInternetSales table.
Declare @Column varchar(500), @tableName varchar(25)
SET @tableName =’FactInternetSales’
SET @Column = ”
select @Column = @Column + Column_Name + ‘, ‘ from [AdventureWorksDW2014].INFORMATION_SCHEMA.COLUMNS
select ‘SELECT ‘ + SUBSTRING(@Column, 0, LEN(@Column)) + ‘ From ‘+@tableName as SELECTScript
Copy and paste the result and execute the script.