Solved

SQL query select statement to get table headers only

Posted on 2011-09-02
8
756 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how the fundamental information of how to create a table.

777 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