all groups > sql server programming > january 2007 >
You're in the

sql server programming

group:

How do you determine if a field exists?


RE: How do you determine if a field exists? gary7584
1/30/2007 4:01:00 PM
sql server programming:
select *
from syscolumns
where id = object_id ('yourtablename')
and name = 'yourcolumnname'

[quoted text, click to view]
Re: How do you determine if a field exists? Mike C#
1/30/2007 6:47:16 PM
INFORMATION_SCHEMA, syscolumns, sys.columns, etc.

[quoted text, click to view]

How do you determine if a field exists? Rico
1/30/2007 11:38:12 PM
Hello,

I'm trying to write a script to update a series of tables. Is there any way
to determine if a field exists in a particular table?

Any direction would be appreicated.

Thanks!
Rick

Re: How do you determine if a field exists? Rico
1/31/2007 1:06:16 AM
Thanks Gary, very much appreciated!

Rick

[quoted text, click to view]

RE: How do you determine if a field exists? Alejandro Mesa
1/31/2007 6:16:01 AM
Rico,

you can also use function COLUMNPROPERTY with a valid property, which return
NULL if the column does not exists. Be careful with 2005 version, because it
can also return NULL if you do not have permission to view the object.

use northwind
go

select
columnproperty(object_id('dbo.Orders'), 'OrderID', 'ColumnId'),
columnproperty(object_id('dbo.Orders'), 'OrderIDD', 'ColumnId')
go


AMB


[quoted text, click to view]
AddThis Social Bookmark Button