Solved

SQL query select statement to get table headers only

Posted on 2011-09-02
8
746 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
 
LVL 6

Expert Comment

by:markterry
ID: 36476333
Select column_Name  from information_Schema.columns where table_name = 'TableName'
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now