Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning field names and field types from a view...

Status
Not open for further replies.

mmorancbt

IS-IT--Management
Nov 11, 2002
367
US
I am not sure whether this should be in the Microsoft Access forum or here but I will try here first.

I want to return a list of views and then when selected, the field names and field data types from the selected views.

How is this best done?

Thanks.

Matthew Moran
Read my career blog at: Career Blog: Todo esta bien.. Todo esta divertido (it's all good, it's all fun)
 
Here is an example

use pubs

select t.TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,* from information_schema.tables t
join information_schema.columns c on t.TABLE_NAME= c.TABLE_NAME
where t.TABLE_TYPE='VIEW'

Denis The SQL Menace
SQL blog:
Personal Blog:
 
So if you want only the views the query would be

select t.TABLE_NAME from information_schema.tables t
where t.TABLE_TYPE='VIEW'

and then you would run the second query like this

select t.TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,* from information_schema.tables t
join information_schema.columns c on t.TABLE_NAME= c.TABLE_NAME
where t.TABLE_TYPE='VIEW'
and t.TABLE_NAME = @SomeViewName

Denis The SQL Menace
SQL blog:
Personal Blog:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top