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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is the Column there 2

Status
Not open for further replies.

midavis

Programmer
Feb 26, 2004
4
0
0
US
How do you check to see if a column exists in a table before you call it in a stored procedure??

In VB you can traverse the columns object, but in SQL I can't find the secret. I've looked thru sysobjects but don't see columns.

Thanks Mike
 
Try this

select * from INFORMATION_SCHEMA.COLUMNS where table_name = 'tblname' and column_name = 'colname'


Sunil
 
If you are using SQL 2000, check out the INFORMATION_SCHEMA views provided. They are an excellent source of system metadata.

There are numerous functions provided. Also check out functions, meta data and functions, system in BOL. Good luck.

--Angel [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
I wrote code that uses the syscolumns and systables. and that seems to be working.

I will try your example but I think what you wrote is for vb/vba. I have used the schema in vba.

Thanks to both of you.

MikeD
 
Angel,
Are you from Tampa? I lived on AnnaMaria for a while and then moved south to Manasota Key. Back in Chicago now.

Mike
 
Teh INFORMATION_SCHEMA views are new to SQL2000. Don't get too comfortable querying the system tables directly. Microsoft keeps threatening to change the structure of them without notice. However, they have also said that the INFORMATION_SCHEMA views will not change.

I am indeed in Tampa Bay (St Petersburg) - one of the few Florida natives remaining in the state. I can't move up north. Anything below 70 degrees is cold to me. LOL

--Angel [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top