Get the coulmn name from the view in sql server [Resolved]

Posted by Venkatesh under Sql Server on 8/23/2013 | Points: 10 | Views : 954 | Status : [Member] | Replies : 3
Hi,

How to get all the coulmn of particular view in sql query.

Thanks,
Venkatesh.P




Responses

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

Up
0
Down

Resolved

SELECT v1.name

FROM sys.columns v1
INNER JOIN sys.views v2 on V1.OBJECT_ID = V2.OBJECT_ID
and V2.NAME = 'ViewName '


--Method2:

SELECT column_name AS ALIAS, data_type AS TYPE
FROM information_schema.columns
WHERE table_name = 'ViewName'


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

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

Posted by: Bandi on: 8/23/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
--Method3:
SELECT c.NAME

FROM sys.columns c
JOIN sys.objects o ON c.OBJECT_ID = o.OBJECT_ID
where type='V' AND o.NAME='ViewName '


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

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

Posted by: Bandi on: 8/23/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi Venkatesh,
What about Method3 ... That is also alternate query to get list of columns in the given view

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

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

Login to post response