?
Solved

SQL query select statement to get table headers only

Posted on 2011-09-02
8
Medium Priority
?
777 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 33

Assisted Solution

by:knightEknight
knightEknight earned 664 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 668 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
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 668 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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 combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

765 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