Solved

SQL query select statement to get table headers only

Posted on 2011-09-02
8
762 Views
Last Modified: 2012-05-12
Hi,

I am looking for a sql query select statement to get table headers only.  
Any idea?

Thank you,
RD11
0
Comment
Question by:RD11
8 Comments
 
LVL 33

Assisted Solution

by:knightEknight
knightEknight earned 166 total points
ID: 36476316
what do you mean by headers?  do you mean the column names?

select *
from myTable
where 1=0
0
 
LVL 50

Assisted Solution

by:Lowfatspread
Lowfatspread earned 167 total points
ID: 36476317
select * into #temp from yourtable
where 0=1
select * from #temp



or you could query the information_schema.columns view for the column names...

select column_name from information_schema.columns
where table_name='xxxxx'
order by ordinal_number
0
 

Author Comment

by:RD11
ID: 36476324
I just want to get the column headers in a table.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 6

Expert Comment

by:markterry
ID: 36476333
Select column_Name  from information_Schema.columns where table_name = 'TableName'
0
 
LVL 6

Expert Comment

by:markterry
ID: 36476338
Just replace the last 'tablename' with a real table name
0
 

Author Comment

by:RD11
ID: 36476367
Does this work in MS Access, I could not run it.  I got an error message that it could not find the schema file.
0
 
LVL 6

Accepted Solution

by:
markterry earned 167 total points
ID: 36476377
Oh, sorry, you put a zone of MS SQL.


Get Access Field names
Sub FieldNames()
    Dim Rst As Recordset
    Dim f As Field
    
    Set Rst = CurrentDb.OpenRecordset("TableName")
    
    For Each f In Rst.Fields
        MsgBox (f.name)
    Next
    Rst.Close
End Sub

Open in new window

0
 

Author Closing Comment

by:RD11
ID: 36476407
All G:):)D Thank you
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question