DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to get the columns in a table?

Execute the following T-SQL example script in Microsoft SQL Server Management Studio Query Editor to demonstrate the generation of the comma-limited column list - columns name - for a table.

-- SQL information_schema views - database metadata
-- SQL information schema columns - mssql columns name
USE AdventureWorks
 
DECLARE  @Schema  VARCHAR(64),
         @Table   VARCHAR(64),
         @Columns VARCHAR(2000)
 
SET @Table = 'Contact'
SET @Schema = 'Person'
 
-- SQL string append - string concatenation
-- SQL make comma-limited list - make csv list
SELECT   @Columns = COALESCE(@Columns + ', ','') + column_name
FROM     INFORMATION_SCHEMA.Columns
WHERE    table_name = @Table
         AND table_schema = @Schema
ORDER BY ordinal_position
 
-- MSSQL columns list for a table
SELECT @Columns
GO
/*
ContactID, NameStyle, Title, FirstName, MiddleName, LastName, Suffix, EmailAddress,
EmailPromotion, Phone, PasswordHash, PasswordSalt, AdditionalContactInfo,
rowguid, ModifiedDate

*/

------------

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE