column names of a table [Resolved]

Posted by Sureshij under Sql Server on 8/31/2013 | Points: 10 | Views : 10860 | Status : [Member] | Replies : 6
what are the different ways to get column names

ij


Responses

Posted by: Bandi on: 8/31/2013 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
1)
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = N'tablename'

2) select * from sys.columns
where object_id =object_id('dbo.tablename')


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Sureshij, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/3/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

try this


CREATE Proc Test
@TableName varchar(200)
as
select stuff((SELECT ','+COLUMN_NAME + ''
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @TableName for XML path ('')),1,1,'') as ColumnNames



Mark as Answer if its helpful to you

Sureshij, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/3/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi Jayakumar,
I have posted same query.... You posted in the form of comma separated values by using stored procedure

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Sureshij, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/3/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
bandi

which one wrong in my Query i post Your query? i have improve that Query
using Xml path so what?


Mark as Answer if its helpful to you

Sureshij, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/3/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi Jayakumar,
There was nothing wrong.... I just replied back to you that yours & mine is same except comma separated values format

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Sureshij, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 9/6/2013 [Member] Starter | Points: 25

Up
0
Down
select * from sys.columns

exec sp_help 'tablename'


sriram

Sureshij, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response