Thursday, September 13, 2007

How to get only Column name returned as result., Info

Sometimes in programming we just need to return the column name for a given table.

To solve this

1. Write a simple query:-

select name from syscolumns where id = object_id ('Typeurtablenamehere')


to see more attributes write
select * from syscolumns where id = object_id ('Typeurtablenamehere')

2. Also other method:-

select * from tablename where 1=0

It will give only the column name as output..


3. Also One more:-

select Column_NAME from information_schema.columns where table_name = 'Typeurtablenamehere'


Add more to this if some other methods is there also.

Enjoy....
..
.

No comments: