Solved

SQL Server 2005 Stored Procedure Get Table Column Names

Posted on 2007-04-03
8
203 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
  • 4
  • 4
8 Comments
 
LVL 142

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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18845259
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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 142

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 142

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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server 2012 r2 - Make Temp Table Query Faster 5 40
Importing Backpac? 1 20
sql 2014,  lock limit 5 29
SQL - Update field defined as Text 6 15
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.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

813 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

16 Experts available now in Live!

Get 1:1 Help Now