Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help me in listing all the columns

Author  Topic 

ganeshkumar08
Posting Yak Master

187 Posts

Posted - 2009-08-28 : 02:21:13
Hi All,

In one SP i pass Database name, Table Name as parameter, based on the parameter i have to display the columns

How to do it..
Please can any one help me.

Thanks
Ganesh

Solutions are easy. Understanding the problem, now, that's the hard part

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-28 : 02:38:24
[code]declare @DatabaseName sysname,
@TableName sysname

select @TableName='geolines', @DatabaseName ='test'

declare @a varchar(200)
set @a = 'SELECT * FROM ' + QUOTENAME(@DatabaseName) + '.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ' + QUOTENAME(@TableName, '''')

exec (@a)[/code]


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-08-28 : 03:36:16
or
declare @DatabaseName sysname,
@TableName sysname

select @TableName='test', @DatabaseName ='test'

declare @a varchar(200)
set @a = QUOTENAME(@DatabaseName) + '..sp_columns ' + QUOTENAME(@TableName, '''')

exec (@a)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -