Solved

SQL Server 2005 Stored Procedure Get Table Column Names

Posted on 2007-04-03
8
208 Views
Last Modified: 2010-03-19
Is there a way I can get the column names from a table in an SQL Server 2005 stored procedure.

ie.
Table_A
Column_A
Column_B
Column_C

Is there a function I can call on Table_A so I can use the column names.
0
Comment
Question by:Fraser_Admin
[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
  • 4
  • 4
8 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18843148
check out the following view:

SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Table_A'
0
 

Author Comment

by:Fraser_Admin
ID: 18845212
Sorry, I guess I should have told you that it is a temporary table
#tmpTable.

This doesn't work for that.  I also tried ##tmpTable, but it didn't work either.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18845259
0
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.

 

Author Comment

by:Fraser_Admin
ID: 18845287
This does nothing, am I missing something???

use scales_fpnb
select *
into #tmpUnits
from
lookup_units

use tempdb
go

select *
from   INFORMATION_SCHEMA.TABLES
where  TABLE_CATALOG = 'tempdb'
and    TABLE_SCHEMA  = USER
and    TABLE_NAME = '#tmpUnits'
go

drop table #tmpUnits
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18845311
hmmm. it worked for me...
0
 

Author Comment

by:Fraser_Admin
ID: 18845353
ok I added a % to the end of #tmpUnits, and I see my temp table, but it is called #tmpUnits__________________________________

So based on that, how do i get the column names?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18845357

use scales_fpnb
select *
into #tmpUnits
from
lookup_units

use tempdb
go

select *
from   INFORMATION_SCHEMA.COLUMNS
where  TABLE_CATALOG = 'tempdb'
and    TABLE_SCHEMA  = USER
and    TABLE_NAME LIKE '#tmpUnits%'
go

drop table #tmpUnits
0
 

Author Comment

by:Fraser_Admin
ID: 18845476
That works perfect.  Thanks
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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 extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

717 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