We help IT Professionals succeed at work.

Looping Through Table Columns in SQL Server

NigelRocks
NigelRocks used Ask the Experts™
on
How do I loop through all the columns in a table in T-SQL?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Can you please be more elaborate on what you are trying to achieve?
FYI: You can use the following query to list all columns for a table

Select *
From INFORMATION_SCHEMA.COLUMNS
Where Table_name = 'TableName'
P.
Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

Commented:
sql 2000 or lower?
select * from dbo.syscolumns
sql 2005 or higher?
select * from sys.columns

both:
select * from information_schema.columns